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.

Link to comment
Share on other sites

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

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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