Jump to content

Recommended Posts

I have been putting together a small project with an MySQL db and php. I am having trouble passing a date variable from a text input into a sql statement within php. I think I am going about this in the right way but I am confused as to what I need to do to finish off the code and make it work.

$data = $_POST['datepicker']; 	//this line gets the string from the form text input box and assigns to var $data
$time = strtotime($data);		//this line converts the string $data to time (strtotime) and = $time unix time stamp	
$mydate = date('Y m d',$time);	//this line formats date into Y m d from the time stamp $time and = $mydate
echo $mydate;					//print to screen as test function to view

and the following sql called from php

$result = mysql_query( //collects that data from the table
								"SELECT Room.roomName, booking.*
								FROM Room, booking
								WHERE (bookingDate = . "$mydate" .) AND booking.roomID = Room.roomID
								ORDER BY roomName, startTime"
								);

 

Thanks in advance for any guidance

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/221555-php-and-mysql/
Share on other sites

Hi,

 

The date is placed in a text box in the following format DD/MM/YYYY from a form on another page.

 

By finish off I mean that this code does not work, the sql statement will not accept the variable $mydate. If I replace this with currdate() the sql works fine so I am guessing that the error is in the php prior to the sql statement?

Link to comment
https://forums.phpfreaks.com/topic/221555-php-and-mysql/#findComment-1146891
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.