Jump to content

[SOLVED] Can't get search results


Eiolon

Recommended Posts

I am working on my first search engine so I made something small to test it.

 

I created a table called "reservations"

 

reservation_id int not null primary key auto_increment,

reservation_date date not null default '0000-00-00'

 

I inserted a date of 1981-09-01 for a test.

 

On search.php I have:

 

          <form id="search" name="search" method="get" action="results.php">
            <table width="100%" border="0" cellspacing="2" cellpadding="2">
              <tr>
                <td width="50">Date:</td>
                <td><input type="text" name="reservation_date" id="reservation_date" /></td>
              </tr>
              <tr>
                <td width="50"> </td>
                <td><input type="submit" name="submit" id="submit" value="Search" /></td>
              </tr>
            </table>
            </form>

 

On results.php I have:

 

<?php 

if (isset($_GET['reservation_date'])) {

require_once('../mysql_connect.php');

$query_reservations = "SELECT * FROM reservations WHERE reservation_date = ".$_GET['reservation_date']."";
$reservations = mysql_query($query_reservations) OR die ('Cannot retrieve date information.');
$row_reservations = mysql_fetch_array($reservations);
$totalrows_reservations = mysql_num_rows($reservations);

}

?>

 

When I enter in the date of 1981-09-01 in the search box and submit, $totalrows_reservations is showing 0 instead of 1.  It is getting the date because I echo it out with <?php echo $_GET['reservation_date'] ?>

 

Any suggestions?

Link to comment
Share on other sites

The query should be like this (or maybe i dont know that date types dont need single quotes)

 

$query_reservations = "SELECT * FROM reservations WHERE reservation_date = '".$_GET['reservation_date']."'";

 

For a more secure version i would clean the input first with mysql_real_escape_string() then query the database.

 

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.