Help with PHP FORM TO UPDATE DATABASE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

Help with PHP FORM TO UPDATE DATABASE

Post 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=-
User avatar
scarabatwork
Forum Newbie
Posts: 6
Joined: Sat Mar 01, 2003 5:34 pm
Location: Dallas, TX
Contact:

Post by scarabatwork »

have you tried adding a space on the line:
'SET descrip = 'lalallalallal'WHERE catid = 4' at
between "'lalallalallal'" and "WHERE"?
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

Post 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
Post Reply