Reputation: 33
I have a Contact Us submission form on my web site (mconchicago.com/Contact_Us).
It is supposed to be set up so that every submission gets an autonumber and a current timestamp. Everyting is working now except the timestamp, which is bringing me to the verge of madness. Each time it is all zeros.
This is what the records look like when uploaded:
http://www.mconchicago.com/Screenshots/Records.jpg
This is how I have the timestamp field configured:
http://www.mconchicago.com/Screenshots/Structure.jpg
And here is my last attempt at making the PHP work:
<?
$id=$_POST['mysql_insert_id()'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$company=$_POST['company'];
$email=$_POST['email'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];
$reason=$_POST['reason'];
$comments=$_POST['comments'];
$timestamp=$_POST['UNIX_TIMESTAMP()'];
mysql_connect("emellis2002.db.9243147.hostedresource.com", "emellis2002", "Newpwd99@") or die(mysql_error());
mysql_select_db("emellis2002") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$id', '$first_name', '$last_name', '$company', '$email', '$address', '$city', '$state', '$zip', '$phone', '$reason', '$comments', 'timestamp')");
Print "Your information has been received. Thank you for getting in touch.<br><br>";
Print "<a href=http://www.mconchicago.com/Contact_Us.html>CLICK HERE</a> to return to our web site."
?>
You can see from the Structure screenshot that I have tried many different syntax combinations without success, looking at many forum postings in the process. What am I missing?
Upvotes: 0
Views: 1542
Reputation: 5820
A couple of points:
$timestamp=$_POST['UNIX_TIMESTAMP()'];
You're looking in the POSTed values for something called UNIX_TIMESTAMP(). You probably intended:
$timestamp = 'UNIX_TIMESTAMP()';
Also:
mysql_query("INSERT INTO `data` VALUES ('$id', '$first_name', '$last_name', '$company', '$email', '$address', '$city', '$state', '$zip', '$phone', '$reason', '$comments', 'timestamp')");
You're trying to insert the string timestamp
into the field. You probably meant $timestamp
Upvotes: 1
Reputation: 7871
It is better to use the MYSQL DEFAULT_VALUE property.
Edit the table and put CURRENT_TIMESTAMP in the DEFAULT_VALUE.
This will insert the current timestamp of the MYSQL Server in the timestamp column everytime there is an insert done in the table.
Upvotes: 1