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
https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/
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.

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.