Forum Moderators: open

Message Too Old, No Replies

database update error

database update error

         

smorales

12:44 am on Feb 27, 2008 (gmt 0)

10+ Year Member



HELP!
I keep getting 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 'set name='Discover Body Wise',date='02/5/2008' ,begin='8:00PM',e

here is my code

<?
include("conn.php");
$mode=$_GET["mode"];
if($mode=="add") {
$name=$_POST["name"];
$date=$_POST["date"];
$begin=$_POST["begin"];
$end=$_POST["end"];
$guest=$_POST["guest"];
$location=$_POST["location"];
$address=$_POST["address"];
$city=$_POST["city"];
$state=$_POST["state"];
$country=$_POST["country"];
$zip=$_POST["zip"];
$host1=$_POST["host1"];
$host1phone=$_POST["host1phone"];
$host2=$_POST["host2"];
$host2phone=$_POST["host2phone"];
$host3=$_POST["host3"];
$host3phone=$_POST["host3phone"];
$host4=$_POST["host4"];
$host4phone=$_POST["host4phone"];
$host5=$_POST["host5"];
$host5phone=$_POST["host5phone"];
$additionalinfo=$_POST["additionalinfo"];

$sql="insert into $events(name, date, begin, end, guest, location, address, city, state, country, zip, host1; host1phone, host2, host2phone, host3, host3phone, host4, host4phone, host5, host5phone, additionalinfo) values('$name', '$date', '$begin', '$end', '$guest', '$location', '$address', '$city', '$state', '$country', '$zip', '$host1', '$host1phone', '$host2', '$host2phone', '$host3', '$host3phone', '$host4', '$host4phone', '$host5', '$host5phone', '$additionalinfo')";
$result=mysql_query($sql,$connection) or die(mysql_error());
header("location: index.php");

} elseif($mode=="update") {
$name=$_POST["name"];
$date=$_POST["date"];
$begin=$_POST["begin"];
$end=$_POST["end"];
$guest=$_POST["guest"];
$location=$_POST["location"];
$address=$_POST["address"];
$city=$_POST["city"];
$state=$_POST["state"];
$country=$_POST["country"];
$zip=$_POST["zip"];
$host1=$_POST["host1"];
$host1phone=$_POST["host1phone"];
$host2=$_POST["host2"];
$host2phone=$_POST["host2phone"];
$host3=$_POST["host3"];
$host3phone=$_POST["host3phone"];
$host4=$_POST["host4"];
$host4phone=$_POST["host4phone"];
$host5=$_POST["host5"];
$host5phone=$_POST["host5phone"];
$additionalinfo=$_POST["additionalinfo"];
$id=$_POST["id"];

$sql="update $event set name='$name',date='$date' ,begin='$begin',end='$end' ,guest='$guest',location='$location' ,address='$address',city='$city' ,state='$state',country='$country' ,zip='$zip',host1='$host1' ,host1phone='$host1phone',host2='$host2' ,host3='$host3',host4='$host4phone' ,host5='$host5',host5phone='$host5phone' ,additionalinfo='$additionalinfo' where id='$id'";
//echo $sql;
$result=mysql_query($sql,$connection) or die(mysql_error());
header("location: index.php");
}
?>

Thank you

[edited by: txbakers at 3:06 am (utc) on Feb. 27, 2008]

[edited by: jatar_k at 3:07 am (utc) on Feb. 27, 2008]
[edit reason] fixed sidescroll [/edit]

phranque

2:19 am on Feb 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], smorales!

did you print out and examine your $sql string?
one of your queries uses $events and the other uses $event - a typo?

leadegroot

2:22 am on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in this fragment, $event is not defined, so the sql may not be getting a table name
When you uncomment the 'echo $sql' what do you see?

smorales

4:34 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



When I uncomment the echo statement i get this error....

update set name='Discover Body Wise',date='02/5/2008' ,begin='8:00PM',end='9:00PM' ,guest='Terry Maracini',location='Starbucks' ,address='5th & Central',city='Prince George' ,state='BC',country='' ,zip='',host1='Rae Kamstra' ,host1phone='962-1614',host2='' ,host3='',host4='' ,host5='',host5phone='' ,additionalinfo='' where id=''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 'set name='Discover Body Wise',date='02/5/2008' ,begin='8:00PM',e

I just need to update the database, am I even on the right track? This is just the script part of the form, do you need to see the rest of it?

ZydoSEO

5:13 pm on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like ID has no value when you perform the update... Notice it says where id='' at the end of the echoed SQL.

Also there is no table name in the resulting SQL. It should say something like UPDATE tablename SET... If 'event' is your tablename then simply remove the '$' from in front of it.

[edited by: ZydoSEO at 5:18 pm (utc) on Feb. 27, 2008]

smorales

5:47 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



I dont see WHERE id="......i do have where id='$id'.

I took off the $ from events but now it just refreshes the page.

rocknbil

6:29 pm on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No look at your output, not the programming select.

additionalinfo='' where id=''You have an error in your SQL syntax

The $id variable is not getting populated.

smorales

8:04 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



Thank everyone. I got it figured out. Works great!