...

View Full Version : Not Formating My Date



CoolAsCarlito
03-10-2010, 02:50 AM
I downloaded a date picker javascript script to help with picking dates for random things however it puts it in my text field as say for example 24-3-210 which is fine however after it does that I want it to take it and format it before I hit my submit button as Y-m-d. I looked on the php.net website and followed what it said but for some reason I didn't come up with the right result. I still had it get put into the DB as 0000-00-00.



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

mlseim
03-10-2010, 03:12 AM
We need to see the whole script, where it gets put into the database.
All you're showing us there is the variable from the form.

Also show us the form as well.

CoolAsCarlito
03-10-2010, 10:21 PM
<?php
$e = <<<here
<script type="text/javascript" src="./jscripts/ajax.js"></script>
<script type="text/javascript" src="./jscripts/ts_picker.js"></script>
here;
switch ($_REQUEST['option']) {
case 0:
echo $e;
?>
<h1 class=backstage>Show Booking Management</h1><br />
<form name="eventbooker" method="post">
<input type="hidden" name="action" value="eventbooker" />
<table width="100%" class="table2">
<tr>
<td width="150" valign="center" class="rowheading">Show Name:</td>
<td class="row3">
<select name="event" class="dropdown">
<option value="Null">- Select -</option>
<?php
$query = "SELECT * FROM efed_list_shownames";
$result = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$row['id']."\">".$row['name']."</option>\r";
}
?>
</select></td>
<td class="row3" width="180"><span class="reduced">Set up in show Name Manager</span></td>
</tr>
<tr>
<td width="150" valign="center" class="rowheading">Label:</td>
<td class="row3" id="labelholder"><input type="text" name="label" class="fieldtext40"/></td>
<td class="row3" width="180"><span class="reduced">e.g. Consecutive Number, Date</span></td>
</tr>
<tr>
<td width="150" valign="center" class="rowheading">Air Date</td>
<td class="row3"><input type="text" name="bookingdate" class="fieldtext80" value=""><a href="javascript:show_calendar(document.eventbooker.bookingdate, document.eventbooker.bookingdate.value);"><img src="http://www.defiantwrestling.net/backstage/images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick the date"></a></td>
<td class="row3"><span class="reduced">dd-mm-yyyy</span></td>
</tr>
<tr>
<td class="rowheading" width="150" valign="center" class="rowheading">No. of Matches:</td>
<td class="row3"><input type="text" name="numberofmatches" class="fieldtext40"></td>
<td class="row3"><span class="reduced">More can be added later</span></td>
</tr>
<tr>
<td class="rowheading">Country</td>
<td class="row3" colspan="2">
<select name="countryid" class="dropdown" onchange="ajaxpage('backstageajax.php?random=625094862&routine=arenas&countryid='+this.value,'arenaajax');">
<option value=0>- Select -</option>
<?php
$query = 'SELECT * FROM efed_list_arenas_countries';
$result = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$row['id']."\">".$row['country']."</option>\r";
}
?>
</select></td>
</tr>
<tr>
<td class="rowheading">Arena</td>
<td class="row3" colspan="2"><div id="arenaajax">
<select name="arenaid" class="dropdown">
<option value="0">- Select Arena -</select>
</div></td>
</tr>
</table><br />
<input type="hidden" name="newadded" value="true">
<input type="submit" value="Add Booking" class="button"></form><br />
<input type="button" value="Return to Booking Manager" class="button200"><br /><br />
<?php
returnmain();
break;
}
function eventbooker() {
if ((!empty($_POST['newadded']))) {
$event = mysql_real_escape_string($_POST['event']);
$label = mysql_real_escape_string($_POST['label']);
$bookingdate = mysql_real_escape_string($_POST['bookingdate']);
$numberofmatches = mysql_real_escape_string($_POST['numberofmatches']);
$arenaid = mysql_real_escape_string($_POST['arenaid']);
$query = "INSERT INTO `efed_content_booking` (event_id,label,status_id,bookingdate,arena_id,matches) VALUES ('".$event."', '".$label."', 1, '".$bookingdate."', '".$arenaid."', '".$numberofmatches."')";
mysql_query($query);
}
}
?>

Fou-Lu
03-11-2010, 07:44 PM
I'd check to see if the datepicker lets you format it differently.
With PHP, you'll need to split those out, and you can either just shift them around treating it as a string, or use a mktime to create a timestamp out of it. Sadly, the format dd-mm-yyyy is not recognized under the GNU date input formats, so strtotime is out.


list($day, $month, $year) = explode("-", $_POST['bookingdate']);
$bookingdate = sprintf('%d-%d-%d', $year, $month, $day);


To do this prior to hitting PHP, you'll need to use javascript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum