Jump to content

Archived

This topic is now archived and is closed to further replies.

timetomove

taking dates from PHP into a mysql statemnt - please

Recommended Posts


PHP Freaks Forums
Hello timetomove August 02, 2006, 03:37:05 pm *
Show unread posts since last visit.
Show new replies to your posts.
Total time logged in: 3 minutes.
News: We have DITCHED Invisionboard and converted to SMF. There are issues with signatures and some posts. Please do your best to help cleanup around here and move the conversion along.

  Home   Help Search Profile My Messages Members Logout
PHP Freaks Forums > PHP Discussions > PHP SQL > Start new topic
Using Date from PHP dropdown form in mySQL
Hi there.

How about this one then??
I was wondering if anyone knew why this isnt working. I think its an error in my syntax, maybe a missing " or something?HuhHuh??

While checking the availability of rental cars on a date.
I'm trying to pass a choosen date from a dropdown form into a mySQL statement.
The statement doesnt seem to be reading the $date variable. Any suggestions would be GREATLY appreciated.


THE FORM:


<form id="date_form" action="availability_action.php">
<select name="day">
<optgroup label="Day">
<?php
for ($i=1; $i <= 31; $i++)
  {
  echo "<option value=\"$i\">$i</option>";
  }
?>
</optgroup>
</select>
<select name="month">
<optgroup label="Month">
<?php
for ($i=1; $i <= 12; $i++)
  {
  echo "<option value=\"$i\">$i</option>";
  }
?>
</optgroup>
</select>
<select name="year">
<optgroup label="Year">
<?php
for ($i=2000; $i <= 2010; $i++)
  {
  echo "<option value=\"$i\">$i</option>";
  }
?>
</optgroup>
</select>



<input type="submit" value="Go!" />
</div>
</form>


THE ACTION:

$date = $_POST['year'].str_pad($_POST['month'], 2, '0', STR_PAD_LEFT).str_pad($_POST['day'], 2, '0', STR_PAD_LEFT);


$results = mysql_query("SELECT car
FROM car_table
LEFT JOIN booking_table ON car_table.car = booking_table.car
WHERE $date NOT
BETWEEN booking_table.start
AND booking_table.end")

OUTPUT RESULTS:

while ($row = mysql_fetch_assoc($results))
  {
  $output .= '<tr>'."\n";
  $output .= '<td class="col_1">'.$row['car'].'</td>'."\n"; 
  $output .= '</tr>'."\n";
  }


The output is showing ALL the cars in the car_table and not paying any attention to my $date variable!


I hope Ive described my problem clearly and really would be most grateful if anyone could give me any pointers. I tried concetenating .'115959' onto the end of the $date parameters as my dates are in yyyymmddhhmmss format but I wasnt sure if that was neccessary.. it didnt do anything.

Thanks,

Tim

Share this post


Link to post
Share on other sites
Please post the echoed output of the query string itself.

Share this post


Link to post
Share on other sites

×

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.