Jump to content

wrong or missing date when updating table


jeff5656

Recommended Posts

I'm trying to update the table "icu" before sening out an email with the MAIL command.

I want to today's date to the datesent variable in that table (and that field is set in a DATE format).

However, When I echo datesent it is blank, but when I go to phpmyadmin, the value is "2006-03-09"

What am I doing wrong?  This is strange.  Today's date is 6/3/2009.

The echo is blank but then the field gets populated by a date that is the wrong date!

Here's the code:

 

$current_date = date ("m/d/y");
$id_incr = $_POST['id_incr'];
$whoto = $_POST['whoto'];
$message = $_POST['emailcontent'];

include ('../consults/connectdb.php');
$query = "SELECT * FROM `staff` WHERE `staff_name` = '". $whoto ."' ";
$result = mysql_query ($query) or die ("Invalid query: " . mysql_error ());
$row = mysql_fetch_array ($result);


$to = $row['email'];
$subject = "Notification of ICU admission";
$headers = "From: [email protected]";
$headers = "MIME-Version: 1.0\r\n";



include "connectdb.php";
$sql = "UPDATE icu SET sentemail = 'y', datesent = '$current_date' WHERE id_incr = '$id_incr'";

if (isset($sql) && !empty($sql)) {
$result = mysql_query($sql) or die ("Invalid query: " . mysql_error());

}


$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully to " . $to . "<br>" ;

1. What echo? I don't see any.

I was trying to echo datesent so that's why the echo was blank. sorry, I since took out the echo line.

2. You're including a '../consults/connectdb.php' and 'connectdb.php'? Are they both different MySQL connections? Are the file paths correct?

 

Yes the paths are correct; I have to access ../consults/connectdb.php' because that file accesses a different database (containing the table "staff") than the one in the current directory (also called connectdb.php).

All the fields in ICU are correct except the datesent has a date from 2006.  Weird.

A DATE data type is YYYY-MM-DD. You are attempting to put a m/d/y into it.

 

Your $current_date code should be the following to supply the correct format (you can also just use the mysql CURDATE() function in your query, no php code is necessary) -

 

$current_date = date("Y-m-d");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.