Jump to content

PHP Booking form


M0n5terBunny

Recommended Posts

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
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
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
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
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
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
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.