donglijuan8227 2018-09-24 16:16
浏览 32
已采纳

在echo上查找打印变量$ email的不成功

HTML

<form name="display" action="update.php" method="POST" >
    <li>Account Email:<input type="text" name="find_email" /></li>
    <li><input type="submit" name="submit" /></li>
</form>

PHP

<?php

$db     = pg_connect("host=localhost port=5432 dbname=CS2102 user=xxx password=xxx");
$email = $_POST['find_email'];
$query = "SELECT * FROM user";
$result = pg_query($db, $query) or die("Cannot execute query: $query
");       // Query template
$row    = pg_fetch_row($result);        // To store the result row
$count = pg_query($db, "SELECT count(*) FROM user");
if($db) echo "db connected" . "num of data " . pg_num_rows($count) ." . $email;

if (isset($_POST['submit'])) {
            echo "<ul><form name='update' action='update.php' method='POST' >
            <li>New Password:</li> 
            <li><input type='text' name='new_password' value='$row[password]' /></li>
        <li><input type='submit' name='new' /></li>
        </form>
    </ul>";
}

$password = $_POST['new_password'];
$email = $_POST['find_email'];
echo $email;
if (isset($_POST['new'])) { // Submit the update SQL command
    echo $password; 
    $sql = "'UPDATE user SET password = '$password'' WHERE email = '$email'";
    echo $sql . ":)";

}

It prints:

'UPDATE user SET password = '555'' WHERE email := '':)

But the prior $email that I echo out went missing when I fill up the second form and click submit.

  • 写回答

1条回答 默认 最新

  • dongyanpai2701 2018-09-24 16:51
    关注

    Try adding the email in the update password form too. In PhP, the variable wont be saved if the page refreshes, so you have to save it and again send it to process further. Please have a look at the following update.

    P.S. Added hidden field in the second form to save the posted email from first form

    if (isset($_POST['submit'])) {
                echo "<ul><form name='update' action='update.php' method='POST' >
                <li>New Password:</li> 
                <input type='hidden' name='find_email' value='$_POST['find_email']' />
                <li><input type='text' name='new_password' value='$row[password]' /></li>
            <li><input type='submit' name='new' /></li>
            </form>
        </ul>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址