xux Posted August 30, 2006 Share Posted August 30, 2006 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 usemysql_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 Quote Link to comment Share on other sites More sharing options...
fenway Posted August 30, 2006 Share Posted August 30, 2006 Strange.. if this from PHP or MySQL that you're saying that it's not updated? Quote Link to comment Share on other sites More sharing options...
xux Posted August 30, 2006 Author Share Posted August 30, 2006 YEs,i cant find the new data in the database,although it was reporting database updated.Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted August 30, 2006 Share Posted August 30, 2006 Whoa... no where clause? Quote Link to comment Share on other sites More sharing options...
xux Posted August 31, 2006 Author Share Posted August 31, 2006 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 usemysql_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. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 31, 2006 Share Posted August 31, 2006 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! Quote Link to comment Share on other sites More sharing options...
andyg666 Posted August 31, 2006 Share Posted August 31, 2006 if i'm not mistaken, and i could be, the proper syntax is...[code]$query = "UPDATE news SET news_content=".$content."";[/code] Quote Link to comment Share on other sites More sharing options...
xux Posted August 31, 2006 Author Share Posted August 31, 2006 Thanks for your time,let me try it out.C ya later ;D Quote Link to comment Share on other sites More sharing options...
fenway Posted August 31, 2006 Share Posted August 31, 2006 Yes, that will work too -- still, there's no WHERE clause. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.