dqba94619 2018-07-02 15:18
浏览 15
已采纳

使用POST无法使用$ var回显html <form>

new to php here so i apologize if the solution is super simple. I'm working on a password reset page, it will be the page the user lands on after clicking the email with the token. the issue is the form is not sending the value of $token, its just sending the string.

<?php 

    if(isset($_GET["email"]) && isset($_GET["token"])) {

    $connection = new mysqli("localhost", "USER", "PASSWORD", "USERDB");

    $email = $connection->real_escape_string($_GET["email"]);
    $token = $connection->real_escape_string($_GET["token"]);

    $data = $connection->query("SELECT user_id FROM users WHERE user_email='$email' AND user_token='$token'");

        if ($data->num_rows > 0) {

            echo '<html>

<head>

  <meta charset="UTF-8">

  <title>Change Password</title>

    <link rel="stylesheet" href="../css/style.css" media="screen" type="text/css" />

</head>

<body>

  <div class="reset">
    <h1>Password reset</h1>
            <form action="anotherpage.php" method="POST">
     <input type="password" name="pwd" placeholder="Password">
     <input type="hidden" name="token" value="$token">
     <input type="submit" name="submit" class="submit" value="Update">

</form>

</body>
</html>';

        }   else {


            echo "Please check your link!";
        }





    }   else {

        header("Location: ../");
        exit();
    }

 ?>
  • 写回答

2条回答 默认 最新

  • duanhuang2150 2018-07-02 15:25
    关注

    Just an advice... don't echo the htmltags... Is not a good practice... Instead of echo you can do that. And about the token issue will be fixed like this.

    <?php 
    
        if(isset($_GET["email"]) && isset($_GET["token"])) {
    
        $connection = new mysqli("localhost", "USER", "PASSWORD", "USERDB");
    
        $email = $connection->real_escape_string($_GET["email"]);
        $token = $connection->real_escape_string($_GET["token"]);
    
        $data = $connection->query("SELECT user_id FROM users WHERE user_email='$email' AND user_token='$token'");
    
            if ($data->num_rows > 0) {
            ?>
    
    <html>
    
    <head>
    
      <meta charset="UTF-8">
    
      <title>Change Password</title>
    
        <link rel="stylesheet" href="../css/style.css" media="screen" type="text/css" />
    
    </head>
    
    <body>
    
      <div class="reset">
        <h1>Password reset</h1>
                <form action="anotherpage.php" method="POST">
         <input type="password" name="pwd" placeholder="Password">
         <input type="hidden" name="token" value="<?php echo $token;?>">
         <input type="submit" name="submit" class="submit" value="Update">
    
    </form>
    
    </body>
    </html>
    <?php
    
            }   else {
    
    
                echo "Please check your link!";
            }
    
    
    
    
    
        }   else {
    
            header("Location: ../");
            exit();
        }
    
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用