Jump to content

Date not posting...


Matt Ridge

Recommended Posts

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>'
?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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>'
?>

Link to comment
Share on other sites

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'] . '      &nbsp
		<strong>Date Entered: </strong>' . $row['Added_By_Date'] . '      &nbsp
		<strong><a href="viewncmr.php?id=' . $row['id'] . '">View</a></strong>  &#x2666; &nbsp
		<strong><a href="editncmr.php?id=' . $row['id'] . '">Edit</a></strong>  &#x2666; &nbsp
		<strong><a href="printncmr.php?id=' . $row['id'] . '">Print</a></strong>';



  echo '</table>';
  }
     mysqli_close($dbc);
 require_once('../hf/footer.php')

?>
</body>
</html>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.