Jump to content
Larry Ullman's Book Forums

Working With Dates Form (Html) To Mysql


Recommended Posts

Hi all

 

Please excuse the newbie question, but am struggling a little. I'm reading the book and I'm also trying to put the practical lessons into play chapter by chapter into my own project. Hence the question.

 

I've a form with a 'Date of Birth Field' - now I'm in the UK and the format is DD/MM/YY. In MySQl it's YY/MM/DD right? How do I get it to reverse the date?

 

Thanks in advance..

Link to comment
Share on other sites

update to this.

 

I've tried using the php function date_format($STRING IM USING, YY/MM/DD). I get the SQL error that there's also a time stamp expected. 

 

I've thought about creating three fields on the form. Year, Month, Date - then concatenating the results into a single string to put into the database. That seems to have a long code base though. Firstly, validating that each of those fields isn't empty; is numeric and then finally bundling them all together. 

 

Would welcome ideas :D

Link to comment
Share on other sites

Yes thanks I did. I managed to get the code working in the end; but then I figured it was also open to a number of problems. So I created 3 select fields. Date / Month / Year.

 

Then made this code

if ($_POST['udobdate'] == '' && $_POST['udobmonth'] == '' && $_POST['udobyear'] == '') {
$errors[] = 'You forgot to enter your Date of Birth.';
} else {
$udob = $_POST['udobyear'] . '/' . $_POST['udobmonth'] . '/' . $_POST['udobdate'];
$dob = mysqli_real_escape_string($dbc, $udob);
}
 
 
That's done the trick. I'll probably refine it a little more but in terms of functionality - works a treat.
 
Now I'm trying to figure out cookies and sessions that lovely
 
Warning: Cannot modify header information.
 
problem.
 
Even when the cookie is at the top of the page - before any code. Unless of course I'm misunderstanding the book.
Link to comment
Share on other sites

 Share

×
×
  • Create New...