Jump to content

Need help with Mysql and PHP (Matching word with database values)


farban6

Recommended Posts

Here we go, I need to use a query where it uses a posted time value to compare if there are the same times on the posted date value. I want it so the user cant book the same time on the same day as someone before bascially. My input so far is this

 

<?php ob_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Conforming XHTML 1.0 Strict Template</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>


</head>

<body>

<form name="input" action="input.php" method="post">
Subject: <input type="text" name="subject" />
First Name: <input type="text" name="firstname" />
Surname: <input type="text" name="surname" />
Trainer: <input type="text" name="trainer" />
Email: <input type="text" name="email" />
Date: <input type="text" name="event_date" id="date" />
Time: <input type="text" name="event_time" id="time" />
<input type="submit" value="Submit" name="submit" />
</form>
<script type="text/javascript">
$('#date').datepicker();
$('#time').timepicker({});
</script>
<?php


include_once("functions/database.php");

include_once("functions/number.php");


if (isset($_POST["submit"]))	{

echo $_POST['event_date'];
echo mdy2mysql($_POST['event_date']);

echo $_POST['event_time'];
echo time2mysql($_POST['event_time']);


$queryselect = "SELECT * FROM events LIKE '".$_POST['event_time']."'";

if ($queryselect == true)   {

echo "sorry this time is already booked";
        
        }

else {

$query = "INSERT INTO events (subject, firstname, surname, trainer, email, event_date, event_time, status) VALUES('".$_POST["subject"]."', '".$_POST["firstname"]."',
'".$_POST["surname"]."','".$_POST["trainer"]."','".$_POST["email"]."' ,'".mdy2mysql($_POST['event_date'])."','".time2mysql($_POST['event_time'])."', 'pending' ) ";



$result = mysql_query($query, $db_link) or die(mysql_error().'cannot get results!');
        header("Location: input.php");

}


?>

 

can anyone help me ? very much appreciated.

$input = mysql_real_escape_string($_POST['event_time']);

if($input){ // check if submitted
    $sql = "SELECT * FROM `events` WHERE `event_time`='".$input."'";
    $res = mysql_query($sql) or die(mysql_error());
    if(mysql_num_rows($res) > 0){
        echo "Time slot has been previously filled. Try again.\n";
    }else {
        echo "Time slot is vacant.\n";
    }
}else {
    echo "Please provide a time slot.\n";
}

Archived

This topic is now archived and is closed to further replies.

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