Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Not Formating My Date

    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.

    PHP Code:
    $date mysql_real_escape_string($_POST['date']); 

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    PHP Code:
    <?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);
            }
        }
    ?>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •