วัน-เดือน-ปี แสดง แต่เวลาไม่แสดงครับ มี code ด้านในครับ
Code (PHP)
<?php require_once('Connections/apartment.php'); ?>
<?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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbquestion (QTitle, QDetail, QName, QEmail, QDate) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['QTitle'], "text"),
GetSQLValueString($_POST['QDetail'], "text"),
GetSQLValueString($_POST['QName'], "text"),
GetSQLValueString($_POST['QEmail'], "text"),
GetSQLValueString($_POST['QDate'], "date"));
mysql_select_db($database_apartment, $apartment);
mysql_query("SET NAME UTF8");
$Result1 = mysql_query($insertSQL, $apartment) or die(mysql_error());
$insertGoTo = "question_save.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>เชิญตั้งคำถามในกระทู้ถาม-ตอบ</p>
<p> </p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">หัวข้อคำถาม</td>
<td><span id="sprytextfield1">
<input type="text" name="QTitle" value="" size="32" />
<span class="textfieldRequiredMsg">กรุณากรอกข้อมูลให้ครบด้วยครับ</span></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">รายละเอียด</td>
<td><textarea name="QDetail" cols="50" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ชื่อผู้ถาม</td>
<td><span id="sprytextfield2">
<input type="text" name="QName" value="" size="32" />
<span class="textfieldRequiredMsg">กรุณากรอกข้อมูลให้ครบด้วยครับ</span></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">อีเมล</td>
<td><input type="text" name="QEmail" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input name="btnSubmit" type="submit" id="btnSubmit" value="เพิ่มคำถาม" />
<input name="btnReset" type="reset" id="btnReset" value="ล้างข้อมูล" /></td>
</tr>
</table>
<input type="hidden" name="QDate" value="<?=date("Y-m-d H:I");?>" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {validateOn:["blur"]});
</script>
</body>
</html>
Tag : PHP
Date :
2013-03-10 18:40:14
By :
patz8899
View :
728
Reply :
2
ดูยากครับ ขออนุญาติใส่โค๊ดให้
Code (PHP)
<?php require_once('Connections/apartment.php'); ?>
<?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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbquestion (QTitle, QDetail, QName, QEmail, QDate) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['QTitle'], "text"),
GetSQLValueString($_POST['QDetail'], "text"),
GetSQLValueString($_POST['QName'], "text"),
GetSQLValueString($_POST['QEmail'], "text"),
GetSQLValueString($_POST['QDate'], "date"));
mysql_select_db($database_apartment, $apartment);
mysql_query("SET NAME UTF8");
$Result1 = mysql_query($insertSQL, $apartment) or die(mysql_error());
$insertGoTo = "question_save.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>เชิญตั้งคำถามในกระทู้ถาม-ตอบ</p>
<p> </p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">หัวข้อคำถาม</td>
<td><span id="sprytextfield1">
<input type="text" name="QTitle" value="" size="32" />
<span class="textfieldRequiredMsg">กรุณากรอกข้อมูลให้ครบด้วยครับ</span></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">รายละเอียด</td>
<td><textarea name="QDetail" cols="50" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ชื่อผู้ถาม</td>
<td><span id="sprytextfield2">
<input type="text" name="QName" value="" size="32" />
<span class="textfieldRequiredMsg">กรุณากรอกข้อมูลให้ครบด้วยครับ</span></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">อีเมล</td>
<td><input type="text" name="QEmail" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input name="btnSubmit" type="submit" id="btnSubmit" value="เพิ่มคำถาม" />
<input name="btnReset" type="reset" id="btnReset" value="ล้างข้อมูล" /></td>
</tr>
</table>
<input type="hidden" name="QDate" value="<?=date("Y-m-d H:I");?>" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {validateOn:["blur"]});
</script>
</body>
</html>
type ที่เก็บวันที่ของคุณมันเป็น date ครับ มันจะเก็บได้เฉพาะ วันที่ใน format yyyy-mm-dd หากคุณต้องการที่จะเก็บเวลาด้วยต้องเปลี่ยน type ของฐานข้อมูลเป็น datetime ครับ
ประวัติการแก้ไข 2013-03-10 18:50:55
Date :
2013-03-10 18:45:27
By :
jackkichan
ขอบพระคุณมากครับ
Date :
2013-03-10 19:13:44
By :
patz8899
Load balance : Server 03