Jump to content

PHP MYSQL update query not updating fields


Applellial

Recommended Posts

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.

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

?>

 

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.

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.