Jump to content


Photo

taking dates from PHP into a mysql statemnt - please


  • Please log in to reply
1 reply to this topic

#1 timetomove

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.


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



#2 fenway

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