spangle1187 Posted December 13, 2010 Share Posted December 13, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/221555-php-and-mysql/ Share on other sites More sharing options...
harristweed Posted December 13, 2010 Share Posted December 13, 2010 What does the date look like that is produces by datepicker? Quote Link to comment https://forums.phpfreaks.com/topic/221555-php-and-mysql/#findComment-1146886 Share on other sites More sharing options...
AbraCadaver Posted December 13, 2010 Share Posted December 13, 2010 What do you mean by "finish off the code and make it work"? Is something not working or you need to know how to get the results and display them? Quote Link to comment https://forums.phpfreaks.com/topic/221555-php-and-mysql/#findComment-1146887 Share on other sites More sharing options...
spangle1187 Posted December 13, 2010 Author Share Posted December 13, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/221555-php-and-mysql/#findComment-1146891 Share on other sites More sharing options...
spangle1187 Posted December 13, 2010 Author Share Posted December 13, 2010 please have a look at the attached php file if that will help explain the problem Quote Link to comment https://forums.phpfreaks.com/topic/221555-php-and-mysql/#findComment-1146895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.