Forum Moderators: open
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]
did you print out and examine your $sql string?
one of your queries uses $events and the other uses $event - a typo?
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?
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]