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 Quote Link to comment 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. Quote Link to comment 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 }; ? Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 something like that. Quote Link to comment 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'; "); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 29, 2011 Share Posted October 29, 2011 show your form code. Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 30, 2011 Share Posted October 30, 2011 what is your table structure? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.