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 Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/ 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? Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-82798 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 Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-82894 Share on other sites More sharing options...
fenway Posted August 30, 2006 Share Posted August 30, 2006 Whoa... no where clause? Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-82988 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. Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-83529 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! Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-83567 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] Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-83582 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 Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-83606 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. Link to comment https://forums.phpfreaks.com/topic/19128-problem-with-updating-my-database/#findComment-83685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.