|
 |
|
ช่วยด้วยค่ะ มีปัญหาเรื่องการ insert วันที่ลงฐานข้อมูลค่ะ (datetime) มันขึ้น 1970-01-01 00:00:00 |
|
 |
|
|
 |
 |
|
มีปัญหาเรื่องการ insert วันที่ลงฐานข้อมูลค่ะ
พอ insert แล้ว มันเป็น 1970-01-01 00:00:00
มันไม่ได้เก็บวันที่ที่ต้องการค่ะ
ใช้ datetimepicker ค่ะ
Code (PHP)
<? session_start();
if($_SESSION['student_id'] == ""){
echo "Please Login!";
exit();
}
mysql_connect("localhost","root","1234");
mysql_select_db("regis");
if($_POST['password'] != $_POST['conpassword']){
echo "Password not Match";
exit();
}
$sql = "INSERT INTO course (course_name,course_type,course_frequency_per_week,course_day) VALUES ('$_POST[course]','$_POST[coursetype]','$_POST[coursefre]','$_POST[day]')";
$sqlQuery = mysql_query($sql);
$datein = date('Y-m-d', strtotime($_POST['id_datetime_picker0']));
$sql1 = "INSERT INTO schedule_course (schedule_datetime) VALUES ('".mysql_real_escape_string($datein)."')";
$sqlQuery1 = mysql_query($sql1);
$sqlup= "UPDATE schedule_course SET course_id = '".trim($_POST['course'])."',course_day_id = '".trim($_POST['day'])."'";
$upquery=mysql_query($sqlup);
if($sql){
echo "<script language='javascript'> alert(' Course Register Success');
</script>";
echo '<script type="text/javascript">window.location = "course.php";</script>';
}else if($sql1){
echo "<script language='javascript'> alert(' Course Register Success');
</script>";
echo '<script type="text/javascript">window.location = "course.php";</script>';
}else{
echo "Error:";
}
mysql_close();
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP

|
|
 |
 |
 |
 |
Date :
2014-08-31 15:32:23 |
By :
Cupcake |
View :
1557 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Code (PHP)
echo $datein
ดูก่อนครับ
ว่ารูปแบบออกมาตามต้องการ ก่อนที่จะ insert ลงฐานข้อมูลหรือเปล่า
|
 |
 |
 |
 |
Date :
2014-08-31 15:41:55 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<? ควรเป็น <?php
mysql_ ฟังก์ชั่นทั้งหลาย ควรเปลี่ยนไปใช้ mysqli_ (อ้างอิง http://php.net/manual/en/function.mysql-connect.php)
$_POST[course] หรือ $_POST[coursetype] หรืออะไรก็ตามที่เป็นการเรียกค่า key ใน array ควรใส่ '...' คลุม เช่น $_POST['course'] เพราะค่า key ข้างในผมเชื่อว่าไม่ใช่ค่า constant ดังนั้นการเรียกใช้ต้องให้ถูกต้องจะได้ไม่มีปัญหาในอนาคต ไม่งั้นคุณจะต้องกลับมาตั้งกระทู้ทำไมบน localhost รันได้บน server จริงรันไม่ได้อีก
เสริมจากคุณคห.ข้างบน ควร echo $_POST['id_datetime_picker0'] ออกมาดูด้วยครับว่ารับค่ามาเป็นอะไร
อยากรู้ว่าวันที่ที่บอกว่าไม่ได้ มีค่าส่งมาเป็นอะไรจะได้เอามาหาเหตุผลต่อไปครับ
|
 |
 |
 |
 |
Date :
2014-08-31 15:50:02 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|