dongtuo3795 2014-09-14 21:54
浏览 21
已采纳

Mysql和PHP我的代码没有正确更新[关闭]

My profile.php is not updating properly. When I click my update button, nothing happens. The table information does not update. Here is my code:

<?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');
}

?>

And also, please help me to put some "Alert message" that will be displayed when you have successfully updated the information. Please give me advice on how to get rid of that error.

  • 写回答

1条回答 默认 最新

  • dqingn8836 2014-09-14 22:07
    关注

    When ever you are using global variables always use single quotes in the square brackets like this:

    $_POST['name']
    

    What you wrote is this

    $_POST[name]
    

    Since you are already using single quotes in you sql query for the variables then using single quotes for the globals in the same query won't work. save them in a variable and then insert it in your query like this

    $name = $_POST['name'];
    

    Hope it helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题