我的个人资料.php没有正确更新。当我单击我的更新按钮时,没有任何反应。表信息不会更新。这是我的代码:
<?php
session_start();
include_once('config.php');
$current_url = base64_encode($url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION['Email'])){
$email = $_SESSION['Email'];
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE customers SET Email='$_POST[email]', Firstname='$_POST[firstname]', Lastname='$_POST[lastname]', Gender='$_POST[gender]', Titlename='$_POST[titlename]', BirthMonth='$_POST[bm]', BirthDay='$_POST[bd]', BirthYear='$_POST[by]', Company='$_POST[company]', CellphoneNumber='$_POST[cn]', PhoneNumber='$_POST[pn]' Province='$_POST[province]', Barangay='$_POST[barangay]', Address1='$_POST[add1]', Address2='$_POST[add2]' WHERE Email='$_POST[hidden]'";
mysqli_query($mysqli,$UpdateQuery);
}
$query = $mysqli->query("SELECT * FROM customers WHERE Email='$email'");
if($query){
while($obj = $query->fetch_object()){
echo '<form action="profile.php" method="POST">';
echo 'Email<input type="text" name="email" value="'.$obj->Email.'"><br />';
echo 'Firstname<input type="text" name="firstname" value="'.$obj->Firstname.'"><br />';
echo 'Lastname<input type="text" name="lastname" value="'.$obj->Lastname.'"><br />';
echo 'Gender<input type="text" name="gender" value="'.$obj->Gender.'"><br />';
echo 'Title name<input type="text" name="titlename" value="'.$obj->Titlename.'"><br />';
echo 'BirthMonth<input type="text" name="bm" value="'.$obj->BirthMonth.'"><br />';
echo 'BirthDay<input type="text" name="bd" value="'.$obj->BirthDay.'"><br />';
echo 'BirthYear<input type="text" name="by" value="'.$obj->BirthYear.'"><br />';
echo 'Company<input type="text" name="company" value="'.$obj->Company.'"><br />';
echo 'CellphoneNumber<input type="text" name="cn" value="'.$obj->CellphoneNumber.'"><br />';
echo 'PhoneNumber<input type="text" name="pn" value="'.$obj->PhoneNumber.'"><br />';
echo 'Province<input type="text" name="province" value="'.$obj->Province.'"><br />';
echo 'Barangay<input type="text" name="barangay" value="'.$obj->Barangay.'"><br />';
echo 'Address1<input type="text" name="add1" value="'.$obj->Address1.'"><br />';
echo 'Address2<input type="text" name="add2" value="'.$obj->Address2.'"><br />';
echo '<input type="hidden" name="hidden" value="'.$obj->Email.'">';
echo '<input type="submit" name="update" value="Update">';
echo '</form>';
}
}
}
else
{
die('Please log in your accoount to view this section');
}
?>
另外,请帮助我添加一些“警报消息”,这些消息将在您成功更新信息后显示。请告诉我如何摆脱这个错误。
答案 0 :(得分:0)
当您使用全局变量时,请始终在方括号中使用单引号,如下所示:
$_POST['name']
你写的是这个
$_POST[name]
由于您已经在sql查询中使用单引号变量,因此在同一查询中使用全局变量的单引号将无法正常工作。将它们保存在变量中,然后将其插入您的查询中,如此
$name = $_POST['name'];
希望有所帮助