PDA

View Full Version : Update table


Mark_W
07-22-2007, 06:28 PM
I have been using this http://www.pixel2life.com/publish/tutorials/94/a_complete_detailed_guide_on_using_mysql_with_php/page3/ tutorial on updating a table with MYSQL, however it doesn't seem to be working for me.

When I run the code I get this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''newscontent' SET 'news_title' = 'Blues see opening win', 'news_brief' = 'Birmin' at line 1

This is the code I have used

if ($submit && $content && $brief && $title) {
///////////////////////////////
$aquery =sprintf("UPDATE 'newscontent' SET 'news_title' = '$title', 'news_brief' = '$brief', 'news_content' = '$content' WHERE 'news_id' = '$id' ");
mysql_query($aquery) or die (mysql_error());
////////////////////////////
}

davidj
07-22-2007, 07:06 PM
too many single quotes

you have this...

UPDATE 'newscontent' SET 'news_title' = '$title', 'news_brief' = '$brief', 'news_content' = '$content' WHERE 'news_id' = '$id' ");


try this

UPDATE newscontent SET news_title = '$title', news_brief = '$brief', news_content = '$content' WHERE news_id = '$id'

Mark_W
07-22-2007, 07:35 PM
Oh is that all. Thanks again David, at least I know I wont make that mistake again.

Mark_W
07-22-2007, 08:43 PM
A quick question not relating to this thread, but does this code:

if (!$_POST['submit'])

Translate to 'If form hasn't been submitted then display the following..'?

davidj
07-22-2007, 08:47 PM
if (!$_POST['submit']) {

/// run this code if form field 'submit' is not set

}

Mark_W
07-22-2007, 09:14 PM
Ok thanks, that will help me with a lot.