New PHP person here..

I am setting up an event registration page. The users must select from two arrival dates for hotel and flights. from my database, I am able to populate a dropdown with the two dates.

"SELECT DATE_FORMAT(firstarrival, '%d %M %Y') as newfirsta, DATE_FORMAT(secondarrival, '%d %M %Y') as newseconda, DATE_FORMAT(firstdepart, '%d %M %Y') as newfirstd, DATE_FORMAT(seconddepart, '%d %M %Y') as newsecondd FROM testevent WHERE  id = ".$id.""

I format the date to make it look nice (if i don't, it shows up as 0000-00-00). The problem is, when I try and insert the record, it shows up as zeros anyway.

Below is the snippet from the drop down. If i need to format the date back, should I do it here or what?

Thanks,

<label>Please Select Your Arrival Date:</label>
<select name="arrivaldate" id="arrivaldate">
<?php foreach ($traveldates as $traveldate) { ?>
<option value="<?php echo htmlentities ($traveldate["newfirsta"]) ?>"><?php echo htmlentities ($traveldate["newfirsta"]) ?>
<option value="<?php echo htmlentities ($traveldate["newseconda"]) ?>"><?php echo htmlentities ($traveldate["newseconda"]) ?>		<?php } ?>
		</select>

You'll want to format the date back prior to doing the insert. So, in the script you use to process the form data, use strtotime to convert the string to a timestamp. Then insert the data.

Thanks...so do I do that with the following line?

$arrivaldate	= mysql_real_escape_string($_POST['arrivaldate']);

?

Yeah, I'd say something like:

$arrivaldate	= mysql_real_escape_string(strtotime($_POST['arrivaldate']));

would work. Try it out and post back.

Well I realized something while working on this. I am retrieving this and storing it in the database as a DATE. It came up with 0000-00-00 even with the last edit and that is what made me look around the database and remember that it is being stored in a date format. If that changes anything, my apologies for omitting that.

Ok, well try this:

$arrivaldate	= mysql_real_escape_string(date("Y-m-d",strtotime($_POST['arrivaldate']));

Perfect!!! I was just about to try something more complicated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.