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.

Link to comment
Share on other sites

$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";
}

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.