gpt4 book ai didi

php - MYSQL更新多表报错

转载 作者:行者123 更新时间:2023-11-30 23:02:07 25 4
gpt4 key购买 nike

我正在尝试更新我正在制作的网站上的成员(member)详细信息,但我不断从更新交易中收到此错误。“您的 SQL 语法有误;请查看与您的 MySQL 服务器版本对应的手册,了解在第 1 行的‘AND member.memberID='6''附近使用的正确语法”

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

<?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
}
?>

请帮忙!!

最佳答案

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

...WHERE memberID=$memberID"

关于php - MYSQL更新多表报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23536968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com