Applellial Posted March 5, 2011 Share Posted March 5, 2011 I have the following PHP script to update two time/date fields in the database. When i run this the fields are not updated. Can anyone see where i m going wrong. <?php $con = mysql_connect("localhost","dbname","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db("my_db", $con); mysql_query("UPDATE msm_content SET created = '2011-01-02 00:00:00', modified = '2011-01-01 00:00:00'"); echo 'Query Updated successfully'; mysql_close($con); ?> Your guidance is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/229631-php-mysql-update-query-not-updating-fields/ Share on other sites More sharing options...
dreamwest Posted March 5, 2011 Share Posted March 5, 2011 Try this and see if you get an error. Also update dosnt have an WHERE clause to update, itll update the entire table <?php if(!$con = mysql_connect("localhost","dbname","dbpassword")){ die('Could not connect: ' . mysql_error()); }else{ echo 'Connected successfully'; } @mysql_select_db("my_db", $con); mysql_query("UPDATE `msm_content` SET `created` = '2011-01-02 00:00:00', `modified` = '2011-01-01 00:00:00' ")or die(mysql_error()); echo 'Query Updated successfully'; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/229631-php-mysql-update-query-not-updating-fields/#findComment-1183119 Share on other sites More sharing options...
sayjoy Posted March 5, 2011 Share Posted March 5, 2011 Try this and see if you get an error: mysql_query("UPDATE msm_content SET created = '2011-01-02 00:00:00', modified = '2011-01-01 00:00:00'") or die ("cannt update ".mysql_error()); if you didnt get an error message, then check the data types of your fields in the database. you can try using data type VARCHAR with field length 30 or using data type text. Quote Link to comment https://forums.phpfreaks.com/topic/229631-php-mysql-update-query-not-updating-fields/#findComment-1183126 Share on other sites More sharing options...
Pikachu2000 Posted March 5, 2011 Share Posted March 5, 2011 Don't use a VARCHAR data type to store a date/timestamp. Use one of the appropriate data types, such as DATETIME. Quote Link to comment https://forums.phpfreaks.com/topic/229631-php-mysql-update-query-not-updating-fields/#findComment-1183129 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.