M0n5terBunny Posted October 29, 2011 Share Posted October 29, 2011 hello, i have a booking form that allows people to book appointments from 0900 to 1800 with 30 min intervals 0900,0930,1000 etc and i was wondering if there is some php code out there that will stop people from booking an appointment at a time that is already booked. any ideas ? cheers Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 when users book that time range, update your database and say its booked. everytime someones tries to book, the script checks the database if the time range has been book. if book, echo error else echo booked. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283221 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 what would be the code for that mysql_query(INSERT INTO client (name,time,date) VALUES (test,1400,2011/10/29); if mysql_query == 1 {echo booked } else { do mysql_query }; ? Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283222 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 something like that. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283224 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 Would that work ? i have tried it and it puts in blank fields in my table include('include/connection.inc'); $name = $_POST['name']; $lname = $_POST['lastname']; $date = $_POST['date']; $time = $_POST['time']; if (!mysql_num_rows($sql) == 1) {echo "booked";} else { $sql2; } $sql2 = mysql_query("INSERT INTO table_1 (name,lastname,age) VALUES ('$name','$lname','$age')"); $sql = mysql_query("SELECT * FROM table_1 WHERE date='$date' AND time='$time'; "); Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283227 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 try this include('include/connection.inc'); $name = $_POST['name']; $lname = $_POST['lastname']; $date = $_POST['date']; $time = $_POST['time']; if (!mysql_num_rows($sql) == 1) {echo "booked";} else { $sql2; } $sql2 = mysql_query("INSERT INTO table_1 (name,lastname,age) VALUES ('$name','$lname','$age')"); $sql = mysql_query("SELECT * FROM table_1 WHERE date='$date' AND time='$time'; "); the codes makes no sense. you are not checking if it its booked. you are also not updating the database. your database table should look like this [ name | lastname | age | date | time ] make it like this then use this code. <?php include('include/connection.inc'); $name = $_POST['name']; $lname = $_POST['lastname']; $date = $_POST['date']; $time = $_POST['time']; $sql = mysql_query("SELECT * FROM table_1 WHERE date='$date' AND time='$time'"); if (mysql_num_rows($sql) != 1) { echo "booked"; } else { $sql2 = mysql_query("INSERT INTO table_1 (name,lastname,age,date,time) VALUES ('$name','$lname','$age','$date','$time')"); } ?> EDIT: just updated Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283232 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 nope still giving blank areas in the table Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283233 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 show your form code. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283236 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 <form name="myForm" action="insert_proc.php" onsubmit="return validateForm()" method="post"> <tr> <td>First Name </td> <td> <input type="text" name="fname"/></td> </tr> <tr> <td>Last Name </td> <td> <input type="text" name="lname"/></td> </tr> <tr> <td>Age </td> <td> <input type="text" name="age"/></td> </tr> <tr> <td>Date </td> <td> <input type="text" name="date"/></td> </tr> <tr> <td>Time </td> <td> <input type="text" name="time"/></td> </tr> <tr> <td> </td> <td> <input type="submit" value="Submit"/></td> </tr> </form> Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283238 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 Do you know the purpose of the function POST? its to get the variables from the input. you calling invalid input previously. <?php include('include/connection.inc'); $name = $_POST['fname']; $lname = $_POST['lname']; $age = $_POST['age']; $date = $_POST['date']; $time = $_POST['time']; $sql = mysql_query("SELECT * FROM table_1 WHERE date='$date' AND time='$time'"); if (mysql_num_rows($sql) != 1) { echo "booked"; } else { $sql2 = mysql_query("INSERT INTO table_1 (name,lastname,age,date,time) VALUES ('$name','$lname','$age','$date','$time')"); } ?> this should work. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283239 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 Yeh i understand the Function POST , i have tidied up to make it easier to understand. form - insert.php <form method="post" action="insert_proc.php"> First Name<input type="text" name="fname"/> Last Name<input type="text" name="lname"/> Age<input type="text" name="age"/> <input type="submit" value="Submit"/> inser_proc.php <?php include('include/connection.inc'); $name = $_POST['fname']; $lname = $_POST['lname']; $age = $_POST['age']; $sql = mysql_query("SELECT * FROM table_1 WHERE age='$age'"); if (mysql_num_rows($sql) != 1) { echo "booked"; } else { $sql2 = mysql_query("INSERT INTO table_1 (name,lastname,age) VALUES ('$name','$lname','$age')"); } ?> but yet even in simple form and erasing all the entries so the db is blank it echo's booked and wont book it even when there is nothing there. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283241 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 Do you have any data in your database? After this line $name = $_POST['fname']; $lname = $_POST['lname']; $age = $_POST['age']; add this line echo $fname; echo $lname; If you didn't not see anything which is from the previous page then something is wrong with your form Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283278 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 What is in the include? Is there something wrong with the include file? Check if there are any errors. Try directly typing it on the insert_proc.php Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283280 Share on other sites More sharing options...
M0n5terBunny Posted October 30, 2011 Author Share Posted October 30, 2011 this is the only script thats messing up the connection file is solid i have 6 other scripts that work off it and im having no problem with them i have another insert file that inserts users with an md5 password setup and thats working fine Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283482 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 30, 2011 Share Posted October 30, 2011 what is your table structure? Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283500 Share on other sites More sharing options...
PFMaBiSmAd Posted October 30, 2011 Share Posted October 30, 2011 if (mysql_num_rows($sql) != 1) { echo "booked"; ^^^ That logic is wrong. If there is already a row (booked), mysql_num_rows will give 1 (one). You would need to test == 1 for a booked condition. != 1 is a not booked condition. Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1283502 Share on other sites More sharing options...
M0n5terBunny Posted November 3, 2011 Author Share Posted November 3, 2011 <pre># Column Type Collation Attributes Null Default Extra Action 1 name varchar(255) latin1_swedish_ci No None Change Drop More 2 time varchar(4) latin1_swedish_ci No None Change Drop More 3 date date No None Change Drop More 4 issue varchar(255) latin1_swedish_ci No None Change Drop More 5 description varchar(255) latin1_swedish_ci No None Change Drop More 6 booked varchar(255) latin1_swedish_ci No None Change Drop More 7 gsub varchar(3) latin1_swedish_ci No None Change Drop More 8 time_added varchar(255) latin1_swedish_ci No None Change Drop More 9 date_added varchar(255) latin1_swedish_ci No None Change Drop More Link to comment https://forums.phpfreaks.com/topic/250039-php-booking-form/#findComment-1284738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.