Jump to content

Recommended Posts

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

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

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

<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

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

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

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

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

<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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.