|
 |
|
รบกวนช่วยเรื่องเพิ่มการบันทึกเวลาลงฐานข้อมูล php+mysql |
|
 |
|
|
 |
 |
|
คือผมจะเพิ่มการบันทึกเวลาที่เป็นปัจจุบันลงไปในฐานข้อมูลด้วย แต่ไม่รู้ว่าต้องเพิ่มเข้าไปบรรทัดไหนอย่างไรครับ รบกวนช่วยชี้แนะด้วยครับ ขอบคุณครับ
Code (PHP)
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formadd")) {
$insertSQL = sprintf("INSERT INTO production (Process, Customer, Type, Volt, Capacitance, Lotno, Incoming, Outgoing, Ng, Ngapp, Ngcaph, Ngcapl, Ngmark) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['process'], "text"),
GetSQLValueString($_POST['Customer'], "text"),
GetSQLValueString($_POST['type'], "text"),
GetSQLValueString($_POST['voltage'], "text"),
GetSQLValueString($_POST['capacitance'], "text"),
GetSQLValueString($_POST['lotno'], "int"),
GetSQLValueString($_POST['incoming'], "int"),
GetSQLValueString($_POST['outgoing'], "int"),
GetSQLValueString($_POST['ng'], "int"),
GetSQLValueString($_POST['ngapp'], "int"),
GetSQLValueString($_POST['ngcaph'], "int"),
GetSQLValueString($_POST['ngcapl'], "int"),
GetSQLValueString($_POST['ngmark'], "int"));
mysql_select_db($database_ems, $ems);
$Result1 = mysql_query($insertSQL, $ems) or die(mysql_error());
$insertGoTo = "datasave.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-02-21 11:04:11 |
By :
amazor |
View :
2980 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มตัวแปรของเวลาเข้าไปแล้วก็ insert ลงไปในตารางธรรมดาค่ะ
Code (PHP)
$time = date('H:i:s');
|
 |
 |
 |
 |
Date :
2012-02-21 11:19:00 |
By :
teukkead |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ คือผมมีตัวแปรและ Insert แบบนี้อยู่แต่ไม่รู้ถูกหรือเปล่า หรือต้องเอาไปใส่บรรทัดไหน (ผมไม่มีความรู้เรื่องภาษาphpเลย)
ไม่ทราบว่า dreamweaver มีฟังชั่นที่สามารถ insert เวลาเข้าไปที่ฐานข้อมูลได้เลยรึเปล่าครับ
$date = now() //เวลาปัจจุบัน
$Mysql> INSERT INTO date VALUES(NOW() );
|
 |
 |
 |
 |
Date :
2012-02-21 13:21:08 |
By :
amazor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|