gpt4 book ai didi

PHP/MySQL : UPDATE query not working (while SELECT and INSERT INTO work)

转载 作者:行者123 更新时间:2023-11-29 22:21:21 25 4
gpt4 key购买 nike

我有一个问题,现在我花了很长时间试图解决。

虽然 SELECT 和 INSERT INTO 查询一切正常,但我无法在 phpMyAdmin 中更新我的数据库

        <?php

// Vérification de la validité des informations
if (isset($_POST['name_last']) AND isset($_POST['name_first']) AND isset($_POST['email']) AND isset($_POST['school']) AND isset($_POST['phone_number']) AND isset($_POST['birth_date']))
{
// On rend inoffensives les balises HTML que le visiteur a pu rentrer
$_POST['login'] = htmlspecialchars($_POST['login']);
$_POST['name_last'] = htmlspecialchars($_POST['name_last']);
$_POST['name_first'] = htmlspecialchars($_POST['name_first']);
$_POST['email'] = htmlspecialchars($_POST['email']);
$_POST['school'] = htmlspecialchars($_POST['school']);
$_POST['phone_number'] = htmlspecialchars($_POST['phone_number']);
$_POST['birth_date'] = htmlspecialchars($_POST['birth_date']);

$login = $_POST['login'];
$name_last = $_POST['name_last'];
$name_first = $_POST['name_first'];
$email = $_POST['email'];
$school = $_POST['school'];
$phone_number = $_POST['phone_number'];
$birth_dateInput = $_POST['birth_date'];
$birth_date = DateTime::createFromFormat('d/m/Y', $birth_dateInput)->format('Y-m-d');

if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['email']))
{
echo 'L\'adresse ' . $_POST['email'] . ' n\'est pas valide, recommencez !';
}

else {


// Insertion
$req = $bdd->prepare('UPDATE member_student(email, name_last, name_first, school, phone_number, birth_date) SET(:email, :name_last, :name_first, :school, :phone_number, :birth_date) WHERE login = $login');
$req->execute(array(
'email' => $email,
'name_last' => $name_last,
'name_first' => $name_first,
'school' => $school,
'phone_number' => $phone_number,
'birth_date' => $birth_date
));


echo 'Vos changement ont été pris en compte et votre nouvelle école est ' . $school . " " . $login . " " . $email . " " . $name_last . " " . $name_first . " " . $id . " " . $birth_date;
?>

一切似乎都工作正常,没有返回错误,并且网站显示:“Vos changement ont été pris en compte et votre nouvelle école est ...”

但是,phpMyAdmin 中的数据库没有更新!您知道问题可能出在哪里吗?我已经检查了每个变量,与数据库的连接工作正常,所以我认为问题来自 MySQL 查询。

任何帮助将不胜感激:只要我无法使更新查询工作,我就会陷入困境!

最佳答案

替换此代码

$req->execute(array(
`email` => $email,
`name_last` => $name_last,
`name_first` => $name_first,
`school` => $school,
`phone_number` => $phone_number,
`birth_date` => $birth_date
));

在数据库字段中使用此符号`

关于PHP/MySQL : UPDATE query not working (while SELECT and INSERT INTO work),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30681689/

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