View Full Version : Searching an EXACT date
revray
02-24-2008, 03:47 AM
Evening,
I am trying to create a simple query that will take the date that the users enters and compares it to dates entered into the database. It is looking for an exact match on DATE information inside the database and the table. I cannot get this to work, I search for dates that I know are in the database and it returns that it does not find the record. I am using the = in my query, is this the wrong command for date information?
The form is validated for users to enter the date in the right format yyyy-mm-dd, and the I know that it is entered right in the database. Can anyone guide me to the right query to make this work?
Thanks so much in advance! Find the script I am using below.
$usertable = "booking_dates"; // This is the table you made.
$dbName = "turnerbooking"; // This is the main database you connect to.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
$query = mysql_query("SELECT * FROM $usertable WHERE $_POST[date_search] = '%$search%' ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["date"];
//$variable2=$row["row_name2"];
//$variable3=$row["row_name3"];
print ("$variable1");
}
Try this:
$usertable = "booking_dates"; // This is the table you made.
$dbName = "turnerbooking"; // This is the main database you connect to.
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect to database");
mysql_select_db( "$dbName") or die( "Unable to select database");
$query = mysql_query("SELECT * FROM $usertable WHERE {$_POST['date_search']} = '%$search%' ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["date"];
//$variable2=$row["row_name2"];
//$variable3=$row["row_name3"];
print ("$variable1");
}
revray
02-24-2008, 04:24 AM
Nile,
Thanks so much for your help, it did not work however, and I am sure that I am doing something wrong. Here is the whole script, with the changes you suggested, any chance you could guide me further?
$usertable = "booking_dates"; // This is the table you made.
$dbName = "turnerbooking"; // This is the main database you connect to.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
$query = mysql_query("SELECT * FROM $usertable WHERE {$_POST['date_search']} = '%$search%' ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["date"];
print ("$variable1");
}
//below this is the function for no record!!
if (!$variable1)
{
echo "<p> Great news! Jeff is available. Please fill out the form below to contact Jeff about booking your date. Please note, your date IS NOT booked yet, it simply is available. Make sure to fill out this form so Jeff can get back to you.</p>"
;
}
//end
?>
Try this:
$usertable = "booking_dates"; // This is the table you made.
$dbName = "turnerbooking"; // This is the main database you connect to.
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect to database");
mysql_select_db( "$dbName") or die( "Unable to select database");
$query = mysql_query("SELECT * FROM $usertable WHERE {$_POST['date_search']} = '$search' ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["date"];
print ("$variable1");
}
//below this is the function for no record!!
if (!$variable1)
{
echo "<p> Great news! Jeff is available. Please fill out the form below to contact Jeff about booking your date. Please note, your date IS NOT booked yet, it simply is available. Make sure to fill out this form so Jeff can get back to you.</p>"
;
}
//end
?>
revray
02-24-2008, 05:03 AM
I cannot figure out what I am doing wrong!
If i use LIKE, then it lists all the dates that are entered into the database, if I use the = then it says record not found. Where am I messing up?
Well are you sure the value from {$_POST['date_search']} is an entry?
revray
02-24-2008, 05:30 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testing</title>
<link href="bookingformat.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="content">
<p>To see if Jeff is available for your special day, please use this form to input your wedding date.</p>
<form method="post" action="result.php">
<p>Enter your wedding date below to see if Jeff is available</p>
<p> Please note, you must enter your date in the following format yyyy-mm-dd. </p>
<p> <span id="sprytextfield1">
<label>Wedding Date:
<input type="text" name="date_search" id="date_search" />
</label>
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
<input type="submit" value="Check Your Date"></p>
</form>
</div>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {format:"yyyy-mm-dd", hint:"yyyy-mm-dd"});
//-->
</script>
</body>
</html>
This is the form I am using.
revray
02-24-2008, 05:40 AM
WHERE {$_POST['date_search']}
Should the date_search be the name of the field in the search form, or the row in my database or something else?
Thanks again for your time!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.