Another question - edit member database

Here is the code -

[code]<?
$right=$_POST[“right”];
$left=$_POST[“left”];
$add=$_POST[“add”];
$search=$_POST[“search”];
$delete=$_POST[“delete”];
$update=$_POST[“update”];
$id=$_POST[“user_id”];
$name=$_POST[“name”];
$phone=$_POST[“phone”];
$email=$_POST[“user_email”];
$address=$_POST[“address”];
$section=$_POST[“section”];
?>

<? function check_mysql() { if (mysql_errno() > 0) { die("
MySQL error ".mysql_errno()." : ".mysql_error()); } } // set up variables for connection include "login.php"; $mysqlcnx = mysql_connect( $myserver, $myuser, $mypassword); if(!$mysqlcnx) { die("Failed to open connection to MySQL server"); } $mysqldb = mysql_select_db( $mydbase ); if(!$mysqldb) { echo 'Cannot select database.'; exit; } if (!isset($id)) { $id=0; } if (isset($left)) { $query = "select c_id, cname, cphone, cemail, caddress, csection from contacts where c_id < $id order by c_id desc"; $result = mysql_query($query); check_mysql(); $row = mysql_fetch_row($result); check_mysql(); if ($row[0] >0) { $id = $row[0]; $name= $row[1]; $phone=$row[2]; $email=$row[3]; $address=$row[4]; $section=$row[5]; } } elseif (isset($right)) { $query = "select c_id, cname, cphone, cemail, caddress, csection from contacts where c_id > $id order by c_id asc"; $result = mysql_query($query); check_mysql(); $row = mysql_fetch_row($result); check_mysql(); if ($row[0] >0) { $id = $row[0]; $name= $row[1]; $phone=$row[2]; $email=$row[3]; $address=$row[4]; $section=$row[5]; } } elseif (isset($search)) { $id =0; $query = "select c_id, cname, cphone, cemail, caddress, csection from contacts where cname like '%$name%' and c_id > $id"; $result = mysql_query($query); check_mysql(); $row = mysql_fetch_row($result); check_mysql(); if ($row[0] >0) { $id = $row[0]; $name= $row[1]; $phone=$row[2]; $email=$row[3]; $address=$row[4]; $section=$row[5]; } } elseif (isset($add)) { $count=mysql_query("select count(*)+1 from contacts"); $query = "insert into contacts (c_id, cname, cphone, cemail, caddress, csection) values ('$count', '$name', '$phone', '$email', '$address', '$section')"; $result = mysql_query($query); check_mysql(); $id = mysql_insert_id(); $message = "record added (user_id=$id)"; } elseif (isset($update)) { $query = "update contacts set ( cname, cphone, cemail, caddress, csection) values ('$name', '$phone', '$email', '$address', '$section')where c_id = $id"; $results = mysql_query($query); check_mysql(); $message = "Record updated (c_id = $id)"; } elseif (isset($delete)) { $query = "delete from contacts where c_id = $id"; $result = mysql_query($query); check_mysql(); $name=""; $phone=""; $email=""; $address=""; $section=""; $message = "Record deleted (c_id=$id)"; } $email= trim ($email); $name= trim ($name); $phone= trim ($phone); $address= trim ($address); $section= trim ($section); ?>[/code]

the code is intended to scroll through and edit a member database.

I get this error when i run the update function:

MySQL error 1064 : 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 ‘( cname, cphone, cemail, caddress, csection) values (‘joe bloggs’, ‘24753735’, ‘[email protected]’, ‘1 bazz st’, ‘’)’ at line 1

plus i cant scroll right past id # 1.

Any ideas?

syntax for update is:
UPDATE table SET field1=“value1”, field2=“value2”
http://dev.mysql.com/doc/refman/5.0/en/update.html

isset($left) and isset($right) should always return true as they are set by:
$right=$_POST[“right”];
$left=$_POST[“left”];

use
isset($_POST[“left”]) and isset($_POST[“right”])
or
if($_POST[“right”]) $right=$_POST[“right”];
if($_POST[“left”]) $left=$_POST[“left”];

thanks that was a great help!

Sponsor our Newsletter | Privacy Policy | Terms of Service