I am really new at PHP. I have created a form that writes data to a database incuding integet, string and date types.
I need to write a conditional if statement that checks the data posted by the form against the data in the database.
Pls help!
This is what I have so far:
Code: Select all
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("studio_db", $con);
$teststudio = mysql_query("SELECT Room FROM Bookings");
$testslot = mysql_query("SELECT Slot FROM Bookings");
$testdate = mysql_query("SELECT Date FROM Bookings");
$frmstudio = '$_POST[studio]';
$frmslot = '$_POST[slot]';
$frmdate = '$_POST[orderdate]';
if ($teststudio==$frmstudio && $testslot==$frmslot && $testdate==$frmdate)
{
echo "this slot is booked!";
}
else
{
$sql="INSERT INTO Bookings (Room, Slot, Booked, Band, Date)
VALUES ('$_POST[studio]', '$_POST[slot]', '1', '$_POST[band]', '$_POST[orderdate]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
}
?>