PHP - 回声变量问题

时间:2016-03-22 00:18:02

标签: php mysql forms

我有一个表格,其中包含用户电子邮件地址和密码。当用户第一次登录他们的帐户时,我想在页面加载时显示用户的电子邮件。但它没有用。数据不会出现在文本字段中。我相信我的代码应该在理论上有用。

HTML

<section class="container">
        <form id="myform " class="Form" method="post" action="Cus_Account.php" accept-charset="utf-8">

            <!--                    <div id="first">-->
            <input type="text" id="fname" name="fname" value="" required> 
            <input type="text" id="lname" name="lname" value="" required>
            <input type="text" id="email" name="email" value="<?php echo $email; ?>" required>
            <input type="number" id="phone" name="phone" value="" required>
            <input type="submit" name="Update" value="Update">
            <br>
        </form>

PHP

   <?php
        $user = $_SESSION['Cus_Email'];

        $get_user = "SELECT Cus_Email FROM Cus_Register WHERE Cus_Email='$user'";

        $run_user = mysqli_query($dbc, $get_user);
        //check if customer is on databse
        $row_customer = mysqli_fetch_array($run_user);


        $email = $row_customer['Cus_Email'];

        ?>

告诉你我在页面上运行另一个查询也可能有帮助

PHP

      <?php
        if (isset($_POST['Update'])) {
            echo $c_fname = $_POST['fname'];
            echo $c_lname = $_POST['lname'];
            echo $c_phone = $_POST['phone'];



            $insert_det = "INSERT INTO Cus_acc_details(CUS_Fname,CUS_Lname, CUS_Phone) VALUES (?,?,?)";
            $stmt = mysqli_prepare($dbc, $insert_det);

            mysqli_stmt_bind_param($stmt, 'ssi', $c_fname, $c_lname, $c_phone);

            /* execute query */
            $r = mysqli_stmt_execute($stmt);

            if ($insert_det) {
                echo " Saved";
            }
        } else {
            echo "<b> Error </b>";
        }
        ?>

此查询将未在注册页面上收集的数据插入数据库。

错误:

  

未定义的索引:第60行的/Applications/MAMP/htdocs/PhpProject2/customer/Cus_Account.php中的Cus_Email

1 个答案:

答案 0 :(得分:2)

您可以使用var_dump来控制记录数据以生成Cus_Email

如果找不到,可以检查你的sql是否正确。

<?php
    $user = $_SESSION['Cus_Email'];

    $get_user = "SELECT Cus_Email FROM Cus_Register WHERE Cus_Email='$user'";

    $run_user = mysqli_query($dbc, $get_user);
    //check if customer is on databse
    $row_customer = mysqli_fetch_array($run_user);
    // to test
    var_dump($row_customer);
    $email = $row_customer['Cus_Email'];

?>