frank_solo Posted April 12, 2011 Share Posted April 12, 2011 I have a column that is named date_created and has a value of DATETIME. How on this script can I insert only the time it was created. Is it NOW()) and if so how do I write it in the script? // if residential if($_POST['type'] == ""){ mysql_select_db("", $con); $sql = "INSERT INTO apartments (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, service, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['phone'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."')"; $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/233504-timestamp-question/ Share on other sites More sharing options...
gizmola Posted April 12, 2011 Share Posted April 12, 2011 This article should help you understand your options. http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html If you alter your definition from datetime to timestamp you will save space (4 bytes per row) as well as unlocking automatic timestamping of the row. The only issue is that if you will later update these rows, by default an update will also change the timestamp column which may not be what you want. If you leave it as a datetime, then yes you can simply specify the constant 'NOW()' in the VALUES section. Quote Link to comment https://forums.phpfreaks.com/topic/233504-timestamp-question/#findComment-1200659 Share on other sites More sharing options...
frank_solo Posted April 12, 2011 Author Share Posted April 12, 2011 Thank you gizmola your info was very helpful. Quote Link to comment https://forums.phpfreaks.com/topic/233504-timestamp-question/#findComment-1200877 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.