Page 1 of 1

please help with date problem

Posted: Mon Oct 30, 2006 11:49 pm
by ohlaph
Hello, I am writing a script which will allow users to search to see if a date is available or unavailable. I have made a script, but it's not displaying any information, which I don't think it's searching my database. Can someone take a look at this and let me know how to fix it? I'm not sure if I need to do something special with the date feature. Thanks!!!

Code: Select all

<?php

session_start();
include("config.php");

$msg = "";

if (isset($_POST['Submit']))
{
	$event_date = $_POST['event_date'];
	$result = mysql_query("Select * From events where event_date='$event_date'",$con);
	if(mysql_num_rows($result)>0)
	{
		$row = mysql_fetch_array($result, MYSQL_BOTH);
		if($event_date == $row["event_date"])
		{
			$msg = "This date is unavailable";
		}
		else
		{
			$msg = "This date is available";
		}
	}
}

?>

Code: Select all

<html>
<head>
<title>Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

Code: Select all

<?php include "panel.htm"; ?>

Code: Select all

<form name="form1" method="post" action="">
<br /><br /><br />

  <table class="table" width="35%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000">
    <tr> 
      <td colspan="2"><div align="center"><font color="#669966" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>search</strong></font></div></td>
    </tr>
    <tr> 
      <td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Date:&nbsp; </font></div></td>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
        <input name="event_date" id="event_date" width="200">
        </font></td>
    </tr>
    <tr> 

      <td>
        <input type="submit" name="Submit" value="Submit">
      </td>
    </tr>
  </table>
</form>
</body>
</html>

Posted: Mon Oct 30, 2006 11:55 pm
by John Cartwright
What are the values coming from this? How is the user formatting it?

Code: Select all

<input name="event_date" id="event_date" width="200">
Also, how are you storing dates in your database?

We've recently discussed formatting dates and comparing them in a thread, I'll try and dig it up for you.

Posted: Tue Oct 31, 2006 12:00 am
by hc
echo $result;

then run that against your DB. Do you get a return value? Start there, and we'll debug from there

Posted: Tue Oct 31, 2006 12:03 am
by ohlaph
Thanks. The data is coming from an input field:

Code: Select all

<input name="event_date" id="event_date" width="200">
the date is stored in a database as date with 0000-00-00 format. However, I'm going to eventually change the input field to a more modern calendar dropdown feature which will format the date in the input field as it is formatted in the database. But, when I enter even the incorrect date into my search, it displays nothing, which is why I think its not submitting the date.

Thanks a ton for your help!

Posted: Tue Oct 31, 2006 12:48 am
by ohlaph
hc wrote:echo $result;

then run that against your DB. Do you get a return value? Start there, and we'll debug from there
I did that and the result was: Resource id #4

ID#4 is the first row in my database. Any ideas?