Matt Ridge Posted November 22, 2011 Share Posted November 22, 2011 I have an issue with my script, the date for some reason stopped posting after I changed the format in the date() section, I wanted it to post so it shows month-day-year, and it seems for some reason all it accepts is Y-m-d... Can someone help me out here please? <?php require_once('connectvars.php'); if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $PO_Date = date('MM "/" DD "/" YY',strtotime($_POST['PO_Date'])); $query = "INSERT INTO ncmr (PO_Date) VALUES ('$PO_Date')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>The date have been successfully entered</p>'; mysqli_close($dbc); // Clear the score data to clear the form $PO_Date = ""; } echo'<form form id="all" method="post">'; echo '<div id="abd"><span class="b">On: </span><input type="text" name="Added_By_Date" value="" /></div>'; echo '<div id="button"><input type="submit" value="Submit Edits" name="submit" /></div>'; echo '</form>' ?> Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 22, 2011 Share Posted November 22, 2011 please make sure you are using mysqli and not mysql. Quote Link to comment Share on other sites More sharing options...
joe92 Posted November 22, 2011 Share Posted November 22, 2011 Try php.net, it is a wonderful resource, date. If you look down the list you will find which letter you need to input for month-day-year, being just a rearranged version of the Y-m-d you provided, m-d-Y If you wanted it written out longhand like 22nd November 2011 for example you would use, date('js F Y', $variable_holding_time_in_seconds); Quote Link to comment Share on other sites More sharing options...
xyph Posted November 22, 2011 Share Posted November 22, 2011 Are you using a MySQL timestamp? Those have to be in the format YYYY-MM-DD. If you want to SELECT the date in a different format, use DATE_FORMAT http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format Quote Link to comment Share on other sites More sharing options...
Matt Ridge Posted November 22, 2011 Author Share Posted November 22, 2011 I'm using mysquli, as far as I can tell... @joe, I already tried that and it's not posting hence why I am asking here. <?php require_once('connectvars.php'); if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $Added_By_Date = date('MM "/" DD "/" YY',strtotime($_POST['Added_By_Date'])); $query = "INSERT INTO ncmr (Added_By_Date) VALUES ('$Added_By_Date')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>The date have been successfully entered</p>'; mysqli_close($dbc); // Clear the score data to clear the form $Added_By_Date = ""; } echo'<form form id="all" method="post">'; echo '<div id="abd"><span class="b">On: </span><input type="text" name="Added_By_Date" value="" /></div>'; echo '<div id="button"><input type="submit" value="Submit Edits" name="submit" /></div>'; echo '</form>' ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 You do not want to store a date in the database as mm/dd/yyyy. You want it stored as YYYY-MM-DD so you can use the many database functions that are available to work with dates and times. Quote Link to comment Share on other sites More sharing options...
Matt Ridge Posted November 22, 2011 Author Share Posted November 22, 2011 Ok, so how do I show them as M-D-Y then please? Quote Link to comment Share on other sites More sharing options...
xyph Posted November 22, 2011 Share Posted November 22, 2011 Use your background in computer science to check the links to the manual. Posted twice. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 Look at the DATE_FORMAT() function in the list of MySQL functions I linked to above. If you have any trouble with it, let us know. Quote Link to comment Share on other sites More sharing options...
Matt Ridge Posted November 22, 2011 Author Share Posted November 22, 2011 Use your background in computer science to check the links to the manual. Posted twice. My background is not in computer science thank you very much. It's in graphic design, my experience is self taught as an IT and Admin... do you not think I have that site posted as a favorite to attempt to figure things out? I have used that link, and still can't figure it out why it's not posting... hence why I am asking for help. This is the code I'm using now, and as far as I can tell it's not showing correctly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PDI NCMR Admin Panel</title> <link rel="stylesheet" type="text/css" href="../CSS/view.css" /> </head> <body> <div id="all"> <?php //Show the navagation menu require_once('../hf/nav.php'); echo '<hr />'; $NCMR_ID = $_POST['NCMR_ID']; $Nexx_Part_Description = $_POST['Nexx_Part_Description']; $Added_By_Date = date('m-d-Y'($_POST['Added_By_Date'])); // Connect to the database require_once('../connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL Server'); echo '<h2 id="LNCMR">Latest NCMRs </h2>'; echo '<br />'; // Retrieve the data from MySQL $query = "SELECT * FROM ncmr"; $result = mysqli_query($dbc, $query) or die('Error quering database'); while ($row = mysqli_fetch_array($result)) { $NCMR_ID = $row['NCMR_ID']; $Nexx_Part_Description = $row['Nexx_Part_Description']; $Added_By_Date = $row['Added_By_Date']; $id = $row['id']; echo '<table>'; // Display the data echo '<tr><td class="ncmrdata">'; echo '<strong>Name: </strong>' . $row['Nexx_Part_Description'] . '   <strong>Date Entered: </strong>' . $row['Added_By_Date'] . '   <strong><a href="viewncmr.php?id=' . $row['id'] . '">View</a></strong> ♦   <strong><a href="editncmr.php?id=' . $row['id'] . '">Edit</a></strong> ♦   <strong><a href="printncmr.php?id=' . $row['id'] . '">Print</a></strong>'; echo '</table>'; } mysqli_close($dbc); require_once('../hf/footer.php') ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Matt Ridge Posted November 22, 2011 Author Share Posted November 22, 2011 Look at the DATE_FORMAT() function in the list of MySQL functions I linked to above. If you have any trouble with it, let us know. Again, I've looked at the link, I am asking how to incorporate it into the form I posted? I don't know where to put it, and as far as I can tell yours will only work with SQL, the one I am using is mysquli... so not sure how to make this work. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 It doesn't matter if you're using mysql_* or mysqli_* functions, the query string would be the same. When you insert the date into the database, it goes in YYYY-MM-DD format, then when you retrieve it for display, you use the DATE_FORMAT() function in the query string so you don't have to dick with it in php. $query = "SELECT field1, field2, DATE_FORMAT( `field_with_date`, '%m/%e/%Y' ) AS formatted_date FROM table"; The value will be available in the fetched array with the associative index name of 'formatted_date', as that's what the field is aliased as. Quote Link to comment 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.