 |
|
ตอนนี้ตันเรื่องการเช็คไม่ไห้ซ้ำมากครับ ไม่รู้จะทำยังไงต่อดี เป้นโปรเจ็คอันนึงเลยทีเดียว
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<html>
<? include"config.php";?>
<?
$id = $_POST['id'];
$car_license = $_POST['car_license'];
$use_reserve= $_POST['use_reserve'];
$use_position= $_POST['use_position'];
$location = $_POST['location'];
$objective= $_POST['objective'];
$people= $_POST['people'];
$date_start= $_POST['date_start'];
$time_start= $_POST['time_start'];
$date_stop= $_POST['date_stop'];
$time_stop= $_POST['time_stop'];
$surety= $_POST['surety'];
$time_import= $_POST['time_import'];
$select = "select * from reserve where car_license='$car_license'" ;
$result=mysql_query($select);
$row=mysql_fetch_array($result);
$num=mysql_num_rows($result);
if($num >0 ) //เช็คว่ามีรถตรงกับที่เลือกไหม
{
//เช็คว่าวันที่ตรงกับที่เคยมีไหม
//เช็คว่าเวลาตรงหันไหม
//เช็คว่าวันที่คืนตรงกันไหม
//เช็คว่าเวลาคืนตรงกันไหม
//เช็คเวลาระหว่างจองตรงกันไหม
{
echo "<script>alert('ไม่สามารถจองรถได้นะวันที่ $date_start เวลา $time_start ถึงวันที่ $date_stop เวลา $time_stop มีคนจองแล้วนะ');window.location='index.php?show=car_reserve';</script>";exit();
}
}
$sql_new="select id from reserve order by id desc";
$result_new=mysql_query($sql_new);
$row_new=mysql_fetch_object($result_new);
$id=$row_new->id+1;
$sql="select * from reserve order by id desc";
$result = mysql_query($sql) ;
$result = mysql_query("insert into reserve (id,id_reserve,car_license,use_reserve,use_position,location,objective,people,date_start,time_start,date_stop,time_stop,surety,time_import,status_re)
values('$id','resv_00$id','$car_license','$use_reserve','$use_position','$location','$objective','$people','$date_start','$time_start','$date_stop','$time_stop','$surety','$time_import','1')");
if($result) {
echo "<center><font size=\"3\" face='MS Sans Serif'><b>เพิ่มการจองเป็นที่เรียบร้อยแล้วนะเออ </b></font></center>";
echo "<meta http-equiv='refresh' content='2; url=index.php'>"; exit();
}
?>
</html>
ก็ทุกค่ารับมาจาก textbox ครับ ยกเว้น car_license
โดยรับค่า ทะเบียน(car_license) แล้วเอาไปเช็คที่ ตาราง reserve
ว่ามี ทะเบียนนี้ไหม ถ้ามีก็เอามาเช็ค date_start, time_start, date_stop, time_stop
โดยไม่ไห้มันซ้ำกัน ถ้าซ้ำ ก็เด้งว่าจองไม่ได้
หรือถ้ามีวันที่มีการจอง ระหว่าง date_start กับ date_stop ก็ไม่สามารถจองได้
ช่วยแนะนำแนวทางหรือ วิธีการเช็คให้หน่อยครับ
ตอนนี้ตันอย่างมากมายเลยทีเดียว
ยังไงช่วยแนะนำ ให้ผมหน่อยครับ งานนี้เป็นงานหลักเลยทีเดียว
พอดีไม่ได้เก่งอะไรมากมาย เขียนได้แค่งูๆ ปลาๆ อะครับ
ขอบคุณครับ
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2010-09-03 08:13:39
|
 |
 |
 |
 |
Date :
2010-09-03 07:22:23 |
By :
lazorous |
View :
1220 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |