Jump to content

problem with updating my database


xux

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
Link to comment
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.
Link to comment
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!
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.