Jump to content

Archived

This topic is now archived and is closed to further replies.

xux

problem with updating my database

Recommended Posts

Hi Everybody,
                I have a problem updating my database from a web interface using php,no error was reported but the database is not being updated.the code are are below
[code]
<?php
 
  $content = $HTTP_POST_VARS['content'];
  $content = addslashes($content);
 
// connecting to MySQL server
$connection = mysql_pconnect('localhost', 'rit', 'password')
or die ('Unable to connect!');
// selecting database for use
mysql_select_db('dbs') or die ('Unable to select database!');
// create and execute query
$query = 'UPDATE news set news_content="$content"';
$result = mysql_query($query)
or die ('Error in query: $query. ' . mysql_error());
if($result){
print " Database Have Been Updated";
            }
else{
      echo' Database Could Not Be Updated';
  }   

           
?>
[/code]
Your help will be appreciated.Thanks

Share this post


Link to post
Share on other sites
Strange.. if this from PHP or MySQL that you're saying that it's not updated?

Share this post


Link to post
Share on other sites
YEs,i cant find the new data in the database,although it was reporting database updated.Thanks

Share this post


Link to post
Share on other sites
Whoa... no where clause?

Share this post


Link to post
Share on other sites
My code is working,but not perfect.it is inserting $content instead of the string collected from a form/here is my code
[code]
<?php
 
  $content = $HTTP_POST_VARS['content'];
  $content = addslashes($content);
 
// connecting to MySQL server
$connection = mysql_pconnect('localhost', 'root', '')
or die ('Unable to connect!');
// selecting database for use
mysql_select_db('sme_cms') or die ('Unable to select database!');
// create and execute query
$query = 'UPDATE news set news_content="$content"';
$result = mysql_query($query)
or die ('Error in query: $query. ' . mysql_error());
if($result){
print " Database Have Been Updated";
            }
else{
      echo' Database Could Not Be Updated';
  }   

           
?>
[/code]
Thanks for you help so far.

Share this post


Link to post
Share on other sites
Well, that's because you're in single quotes, and your variable won't be interpolated -- either switch to doubles on the outside, or break out the string explicity.  However, you'd still be updating every record in this table!

Share this post


Link to post
Share on other sites
if i'm not mistaken, and i could be, the proper syntax is...
[code]$query = "UPDATE news SET news_content=".$content."";[/code]

Share this post


Link to post
Share on other sites
Thanks for your time,let me try it out.C ya later ;D

Share this post


Link to post
Share on other sites
Yes, that will work too -- still, there's no WHERE clause.

Share this post


Link to post
Share on other sites

×

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.