[英]MYSQL updating multiple tables error
I am trying to update a members details on a website I'm making but I keep getting this error from the update transaction. 我正在尝试更新正在制作的网站上的会员详细信息,但我不断从更新交易中获取此错误。 "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 'AND member.memberID='6'' at line 1" “您的SQL语法有错误;请在与MySQL服务器版本相对应的手册中找到在第1行'AND member.memberID ='6''附近使用的正确语法”
I have tried different ways of coding it but the error is still the same. 我尝试了不同的编码方式,但错误仍然相同。
<?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
}
?>
please help!! 请帮忙!!
Is the memberID field in the table an int rather than a varchar? 表中的memberID字段是int而不是varchar吗? If so, then your code should say this (without the apostrophes around $memberID): 如果是这样,那么您的代码应该这样说(在$ memberID周围没有撇号):
...WHERE memberID=$memberID"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.