Jump to content


taking dates from PHP into a mysql statemnt - please

  • Please log in to reply
1 reply to this topic

#1 timetomove

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 02 August 2006 - 09:07 PM

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.


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

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


$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
BETWEEN booking_table.start
AND booking_table.end")


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.



#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 02 August 2006 - 09:36 PM

Please post the echoed output of the query string itself.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users