Jump to content


Photo

problem with updating my database


  • Please log in to reply
8 replies to this topic

#1 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 30 August 2006 - 11:58 AM

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
<?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';
   }    

             
?> 
Your help will be appreciated.Thanks

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 August 2006 - 01:34 PM

Strange.. if this from PHP or MySQL that you're saying that it's not updated?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 30 August 2006 - 03:12 PM

YEs,i cant find the new data in the database,although it was reporting database updated.Thanks

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 August 2006 - 04:50 PM

Whoa... no where clause?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 31 August 2006 - 03:23 PM

My code is working,but not perfect.it is inserting $content instead of the string collected from a form/here is my 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';
   }    

             
?> 
Thanks for you help so far.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 31 August 2006 - 04:21 PM

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!
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 andyg666

andyg666
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 31 August 2006 - 04:33 PM

if i'm not mistaken, and i could be, the proper syntax is...
$query = "UPDATE news SET news_content=".$content."";


#8 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 31 August 2006 - 05:25 PM

Thanks for your time,let me try it out.C ya later ;D

#9 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 31 August 2006 - 09:09 PM

Yes, that will work too -- still, there's no WHERE clause.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users