|
 |
|
สอบถามเรื่องการ insert ข้อมูล ที่เป็น date ใน mySQL |
|
 |
|
|
 |
 |
|

จะ insert ข้อมูล ตามรูปคับ
ไม่ทราบว่าควรทำอย่างไงข้อมูลใน DB ถึงจะเป็นรูปแบบ 2010-10-22
ผมลองทำแล้วมันเป็น 0000-00-00
Code (PHP)
$insertSQL = sprintf("INSERT INTO tb_questionnaire (qName, qPassword, ansName, ansAmount, dateStart, dateStop, userID) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['qName'], "text"),
GetSQLValueString($_POST['qPassword'], "text"),
GetSQLValueString($_POST['ansName'], "text"),
GetSQLValueString($_POST['ansAmount'], "int"),
GetSQLValueString($_POST['dateStart'], "date"),
GetSQLValueString($_POST['dateStop'], "date"),
GetSQLValueString($_POST['userID'], "int"));
mysql_select_db($database_db_conn, $db_conn);
$Result1 = mysql_query($insertSQL, $db_conn) or die(mysql_error());
}
?>
<?php
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear, $strHour:$strMinute";
}
$strDate = "2008-08-14";
?>
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 { font-family: "DSN ArKorn";
font-size: 24px;
color: #FF0000;
}
.style2 {color: #0000FF}
.style3 {font-family: "DSN ArKorn"; font-size: 24px; color: #0000FF; }
.style5 {font-size: 22px; }
-->
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" id="fm_newCreate" name="fm_newCreate" method="POST">
<span class="style1">สร้างข้อมูล หัวข้อหลักแบบสอบถามของคุณ </span><br />
<br />
<table width="734" border="0" align="left">
<tr>
<td width="344" class="style1 style2"><div align="right" class="style5">
ชื่อแบบสอบถาม :</div></td>
<td width="369"><label>
<input type="text" name="qName" id="qName" size="60"/>
</label></td>
<td width="10"> </td>
</tr>
<tr>
<td class="style3"><div align="right" class="style5">รหัสผ่านสำหรับตอบ :</div></td>
<td><label>
<input type="password" name="qPassword" id="qPassword" />
</label></td>
<td> </td>
</tr>
<tr>
<td class="style3"><div align="right" class="style5">ชื่อกลุ่มผู้ตอบ :</div></td>
<td><label>
<input type="text" name="ansName" id="ansName" />
</label></td>
<td> </td>
</tr>
<tr>
<td class="style3"><div align="right" class="style5">จำนวนคนสำรวจ :</div></td>
<td><label>
<input type="text" name="ansAmount" id="ansAmount" size="15"/>
</label></td>
<td> </td>
</tr>
<tr>
<td class="style3"><div align="right" class="style5">วันเปิดใช้งาน :</div></td>
<td><label></label><label>
<select name="dateStart" size="1" id="y">
<option selected="selected">--ปี--</option>
<option value="2553-">2553</option>
</select>
<select name="dateStart" size="1" id="n">
<option>--เดือน--</option>
<option value="01-">มกราคม</option>
</select>
<select name="dateStart" size="1" id="j">
<option>--วันที่--</option>
<option value="1">1</option>
</select>
</label></td>
<td> </td>
</tr>
<tr>
<td class="style3"><div align="right" class="style5">วันปิดใช้งาน :</div></td>
<td><label></label><label>
<select name="dateStop" size="1" id="dateStop">
<option selected="selected">--ปี--</option>
<option value="2553-">2553</option>
</select>
<select name="dateStop" size="1" id="dateStop">
<option>--เดือน--</option>
<option value="01-">มกราคม</option>
</select>
<select name="dateStop" size="1" id="dateStop">
<option>--วันที่--</option>
<option value="1">1</option>
</select>
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="hidden" name="userID" id="userID" value="<? echo $_SESSION['MM_UserGroup'];?>" /></td>
<td> </td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="submit" id="submit" value="Create" />
</div></td>
<td><label>
<input type="reset" name="reset" id="reset" value="Reset" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="fm_newCreate" />
</form>
</body>
</html>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2010-10-19 12:46:21 |
By :
lengza |
View :
1670 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคับ
|
 |
 |
 |
 |
Date :
2010-10-19 13:01:03 |
By :
lengza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กลับไปดูตัวอย่างที่ผมแนะนำให้อีกครั้งครับ 
|
 |
 |
 |
 |
Date :
2010-10-19 13:49:22 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|