MYSQL更新多个表错误

时间:2014-05-08 08:48:04

标签: php mysql sql forms syntax-error

我正在尝试更新我正在制作的网站上的会员详细信息,但我不断从更新交易中收到此错误。 "您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便使用' AND member.memberID =' 6''''''''''在第1行"

我尝试了不同的编码方式,但错误仍然相同。

<?php 
session_start(); 
include "../includes/connect.php"; 
?> 

<?php 
$memberID = $_POST['memberID']; //retrieve the memberID from the URL  
$firstName = mysqli_real_escape_string($con, $_POST['firstName']); 
$lastName = mysqli_real_escape_string($con, $_POST['lastName']); 
$street = mysqli_real_escape_string($con, $_POST['street']); 
$suburb = mysqli_real_escape_string($con, $_POST['suburb']); 
$state = mysqli_real_escape_string($con, $_POST['state']); 
$postcode = mysqli_real_escape_string($con, $_POST['postcode']); 
$country = mysqli_real_escape_string($con, $_POST['country']); 
$phone = mysqli_real_escape_string($con, $_POST['phone']); 
$mobile = mysqli_real_escape_string($con, $_POST['mobile']); 
$email = mysqli_real_escape_string($con, $_POST['email']); 
$gender = mysqli_real_escape_string($con, $_POST['gender']); 
$newsletter = mysqli_real_escape_string($con, $_POST['newsletter']); 

if ($firstName == "" || $lastName == "" || $postcode == "" || $country =="" || $email     == "" || $gender == "" || $newsletter == "") //check if all required fields have data
{ 
$_SESSION['error'] = 'All * fields are required.'; //if an error occurs intialise a session called 'error' with a msg 
header("location:memberupdate.php?memberID=" . $memberID); //redirect to memberupdate.php 
exit(); 
} 
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) //check if email is valid 
{ 
$_SESSION['error'] = 'Please enter a valid email address.'; //if an error occurs intialise a session called 'error' with a msg 
header("location:memberupdate.php?memberID=" . $memberID); //redirect to memberupdate.php 
exit(); 
} 
else 
{ 
$sql="START TRANSACTION;
    UPDATE member SET firstName='$firstName',lastName='$lastName',phone='$phone',mobile='$mobile',email='$email',gender='$gender',newsletter='$newsletter' WHERE memberID='$memberID'; 
    UPDATE address SET street='$street',suburb='$suburb',state='$state',postcode='$postcode',country='$country' WHERE memberID='$memberID'; 
    COMMIT;"; 
$result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query 

$_SESSION['success'] = 'Member updated successfully.'; //if the member is updated successfully intialise a session called 'success' with a msg 
header("location:memberupdate.php?memberID=" . $memberID); //redirect to memberupdate.php 
} 
?>

请帮助!!

1 个答案:

答案 0 :(得分:0)

表中的memberID字段是int而不是varchar吗?如果是这样,那么你的代码应该这样说(没有$ memberID周围的撇号):

...WHERE memberID=$memberID"