UPDATE php-script

Hi,

I’ve searched this and other sites for a solution, but it doesn’t seem te help me out…

I’ve got this small CMS I’m working at, but the updating won’t work.

Here’s the update-code:

[php]

<? error_reporting(E_ALL); $link = mysql_connect("localhost","root",""); $db="promic"; if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error()); $title = $_POST['ud_title']; $subtitle = $_POST['ud_subtitle']; $body = $_POST['ud_body']; $show = $_POST['ud_show']; $id = $_POST['page']; if($show == "Ja") $show = "1"; if($show == "Nee") $show = "0"; $sql = "UPDATE articles SET title='$title', subtitle='$subtitle', body='$body', show='$show' WHERE article=$id"; $result = mysql_query($sql) or die(mysql_error()); mysql_close(); echo "Updated!"; ?>

[/php]

The query is allright (or I must be missing something here…) but still I get this message:

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 ‘show=‘1’ WHERE article=0’ at line 1

I just don’t get, all variables have a value and the UPDATE-syntax seems allright.

Can someone help me out here?[/code]

What can happen is sometimes when updating something words will contain an '. Like don’t or won’t.

I would echo out the entire update query just to see what you are gettingn then if you can see a problem, post that here and we can see what we can do to help.

Ragster00

Hmm the show seems to cause the trouble. When I remove that part of the query, it works fine.

The ’ is no problem, when I echo the query, all ’ are changed to '.

The show-field is a char-type, without a default value. I’ve tried making it different types of field, but that doesn’t seem to do the trick.

Maybe it’s in the part where the value of Show (Ja or Nee) gets changed to 0 or 1? I’ve tried to remove the quotes there and in the query, no result though.

Here’s the output after editing a small article with only a title and show:

UPDATE articles SET title='Product assortiment', subtitle='', body='', show='1' WHERE article=1

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 'show='1' WHERE article=1' at line 1

I’m getting a bit confused :)

I just checked into it and SHOW is a mysql function. You cannot use MySQL or PHP reserved words. Just change the field name and that should fix your problem.

HTH!

Hehe, never thought of that :D Thanks!

Mano

Sponsor our Newsletter | Privacy Policy | Terms of Service