1
我想更新我正在做的網站上的成員詳細信息,但我一直從更新事務中收到此錯誤。 「您的SQL語法錯誤;請查看與您的MySQL服務器版本相對應的手冊,以便在第1行'AND member.memberID ='6''附近使用正確的語法」MYSQL更新多個表錯誤
我試過不同的它的編碼方式,但錯誤仍然是一樣的。
<?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
}
?>
請幫忙!!
我想你需要使用這個'mysqli_multi_query' –