<?php
require('conn.php');
session_start();
ini_set('default_charset', 'UTF-8');
conopen();
mysql_query("SET NAMES utf8;");
$idedit = $_SESSION['id'] ;
$firstname = mysql_real_escape_string($_POST['firstnameedit']);
$lastname = mysql_real_escape_string($_POST['lastnameedit']);
$email = mysql_real_escape_string($_POST['emailedit']);
$username = mysql_real_escape_string($_POST['usernameedit']);
$password = mysql_real_escape_string($_POST['passwordedit']);
$query = " UPDATE `users` SET `firstname`= '" . $firstname . "',`lastname`='" . $lastname . "',`email`='" . $email . "',`username`='" . $username . "',`password`='" . $password . "', WHERE id = '" . $idedit . "'";
if (mysql_query($query) === true) {
echo '<meta http-equiv="Refresh" content="0; URL=profile.php" />';
}
else {
echo 'wrong';
}
conclose();
?>
我不知道为什么echo
输出不正确。谁能告诉我什么是错的?我正在尝试重定向到profile.php
。什么可能导致查询返回false?
答案 0 :(得分:3)
在where
子句之前有一个额外的逗号。
试试这个:
$query = " UPDATE `users` SET `firstname`= '" . $firstname . "',`lastname`='" . $lastname . "',`email`='" . $email . "',`username`='" . $username . "',`password`='" . $password . "' WHERE id = '" . $idedit . "'";
通常,您应该学会在变量替换后打印出查询,以查看真实查询的内容。执行此操作时,错误通常很明显。
答案 1 :(得分:0)
我认为问题是查询中WHERE
前面的逗号。