|
 |
|
ขอปรึกษาเรื่อง JavaScript ให้เช็คข้อมูลก่อนว่ามีข้อมูลหรือไม่ ถ้ามีให้ msg ฟ้องว่าข้มูลซ้ำ แต่ถ้าใน SQL ยังไม่มีข้อมูล ให้ insert เข้าระบบ ครับ |
|
 |
|
|
 |
 |
|
ขอปรึกษาเรื่อง JavaScript ตอนกดปุ่ม SUBMIT ให้เช็คข้อมูลก่อนว่ามีการจองในช่วงวันนั้นแล้วหรือไม่ ถ้ามีให้ msg ฟ้องว่าข้มูลซ้ำ แต่ถ้าใน SQL ยังไม่มีข้อมูลในช่วงเวลาที่ส่งมา ให้ insert เข้าระบบ ครับได้เลยและ msg ว่าดำเนินการจองเรียบร้อยแล้ว
ยกตัวอย่างนะครับ
STARTDATE ENDTDATE
ห้อง 301 มีคนจ้องในระบบเอาไว้ วันที่ 10/10/2012 - 20/10/2012
และ วันที่ 26/10/2012 - 30/10/2012
แล้วถ้ามีคนมาจองวันที่ 18/10/2012 - 25/10/2012 ตอนนกดปุ่ม SUBMIT ขอให้มี POP UP แจ้งว่า มูลซ้ำ ครับ
แต่ถ้ามีคนมาจองวันที่ 22/10/2012 - 23/10/2012 ตอนนกดปุ่ม SUBMIT ให้ insert เข้าระบบ ครับได้เลยและ msg ว่าดำเนินการจองเรียบร้อยแล้ว ประมาณนี้ครับ รบกวนขอคำแนะนำด้วยนะครับ
ตอนนี้ผมเขียนเป็น INSERT อย่างเดียวครับ มันไม่เช็คอะไรให้ผมเลย
CODE ที่ผมเขียนไว้ครับ
Code
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$insertstartDate = date("Y-m-d",strtotime($startdate));
$insertendDate = date("Y-m-d",strtotime($enddate));
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO history (pt_id, location, dept, startdate, enddate, user_id) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['dept'], "text"),
GetSQLValueString($insertstartDate, "date"),
GetSQLValueString($insertendDate, "date"),
GetSQLValueString($_POST['user_id'], "text"));
mysql_select_db($database_parttime, $parttime);
$Result1 = mysql_query($insertSQL, $parttime) or die(mysql_error());
Tag : PHP, MySQL, jQuery

|
|
 |
 |
 |
 |
Date :
2012-11-16 16:09:03 |
By :
sranuwat |
View :
1143 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
MySQL ตาม Format ที่ถูกต้องควรเป็น DATE / DATE-TIME ครับ รูปแบบ YYYY-MM-DD ส่วนวิธีในกระทู้เก่า ๆ มีเยอะครับ
|
 |
 |
 |
 |
Date :
2012-11-16 21:36:46 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|