farban6 Posted December 1, 2011 Share Posted December 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252253-need-help-with-mysql-and-php-matching-word-with-database-values/ Share on other sites More sharing options...
marcus Posted December 1, 2011 Share Posted December 1, 2011 $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"; } Quote Link to comment https://forums.phpfreaks.com/topic/252253-need-help-with-mysql-and-php-matching-word-with-database-values/#findComment-1293250 Share on other sites More sharing options...
farban6 Posted December 1, 2011 Author Share Posted December 1, 2011 The problem is that I need to do this on a date that the person has posted. Say on the 21/11/2011, then match agiasnt the times. Quote Link to comment https://forums.phpfreaks.com/topic/252253-need-help-with-mysql-and-php-matching-word-with-database-values/#findComment-1293254 Share on other sites More sharing options...
marcus Posted December 1, 2011 Share Posted December 1, 2011 Then use what I gave you and what you already have and combine the two. You can use multiple clauses in your SQL select statement. $sql = "SELECT * FROM `table` WHERE `foo`='bar' AND `bar`='foo'"; Quote Link to comment https://forums.phpfreaks.com/topic/252253-need-help-with-mysql-and-php-matching-word-with-database-values/#findComment-1293256 Share on other sites More sharing options...
farban6 Posted December 1, 2011 Author Share Posted December 1, 2011 Great this worked thank you ! Quote Link to comment https://forums.phpfreaks.com/topic/252253-need-help-with-mysql-and-php-matching-word-with-database-values/#findComment-1293262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.