Page 1 of 1

Help with PHP FORM TO UPDATE DATABASE

Posted: Sat Mar 01, 2003 4:53 pm
by urb
I need help with getting my code correct. I keep getting syntax errors like the following.

You have an error in your SQL syntax near 'SET descrip = 'lalallalallal'WHERE catid = 4' at line 1
UPDATE categories SET name = 'Test'SET descrip = 'lalallalallal'WHERE catid = 4


What I am trying to do is after I have created a category in a table in my database, I would like to be able to edit and update the information that what submitted. I can get as far as being able to overwrite the new updates into the table in the database. The code im using to update the information from a form is as follows.

<?php

$sql = "SELECT * FROM categories WHERE catid = $catid";
@mysql_select_db($database_name_is_here) or die(mysql_error());
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

if (mysql_num_rows($result) < 1) {
echo 'Required information has been deleted.';
} else {
$sql = "UPDATE categories ";
$sql .= "SET name = '".addslashes(trim($name))."'";
$sql .= "SET descrip = '".addslashes(trim($descrip))."'";
$sql .= "WHERE catid = $catid";
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
}

?>


Please help.

Thank you,

Matt Urban

aka -=URB=-

Posted: Sat Mar 01, 2003 5:38 pm
by scarabatwork
have you tried adding a space on the line:
'SET descrip = 'lalallalallal'WHERE catid = 4' at
between "'lalallalallal'" and "WHERE"?

Posted: Sun Mar 02, 2003 12:41 am
by urb
scarabatwork wrote:have you tried adding a space on the line:
'SET descrip = 'lalallalallal'WHERE catid = 4' at
between "'lalallalallal'" and "WHERE"?

thats the error