我有一个问题,我现在想要解决很长时间。
虽然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 changementontétéliveen compte et votrenouvelleécoleest...”
然而,phpMyAdmin中的数据库没有更新! 你知道问题可能来自哪里吗? 我已检查过每个变量,与数据库的连接工作得很好,所以我认为问题来自MySQL查询。
任何帮助都会非常感激:只要我无法使更新查询工作,我就会陷入困境!
答案 0 :(得分:0)
替换此代码
$req->execute(array(
`email` => $email,
`name_last` => $name_last,
`name_first` => $name_first,
`school` => $school,
`phone_number` => $phone_number,
`birth_date` => $birth_date
));
在数据库字段中使用此符号
答案 1 :(得分:0)
$req = $bdd->prepare('UPDATE member_student(email, name_last, name_first, school, phone_number, birth_date)
SET("'.$email.'", "'.$name_last.'", "'.$name_first.'", "'.$school.'", '.$school.', "'.$birth_date.'") WHERE login='.$login);
试试这种方式
答案 2 :(得分:0)
改变这个:
$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 = $bdd->prepare('UPDATE member_student SET email = :email, name_last = :name_last, name_first = :name_first, school = :school, phone_number = :phone_number, birth_date = :birth_date WHERE login = :login');
答案 3 :(得分:0)
试试这真的有用
$ req = $ bdd-&gt; prepare(&#39; UPDATE member_student SET email = ?, name_last = ?, name_first = ?, school = ?, phone_number = ?, birth_date =? 登录=?&#39;);
$ req-&gt;执行(数组($ email,$ name_last,$ name_first,$ school,$ phone_number,$ birth_date,$ login));