douzhaxian1267 2019-04-27 18:32
浏览 111

如果单击提交按钮,则在PHP代码中更新变量的值

I'm doing a simple form where there are two text boxes and when I input the values and click the button, the entered values would be set/updated to the variables in the php code. It updates the values but for that session only and if I refresh the page, I need to input the values again.

When I click submit, it would not show any error and is internally updated but the old/default values of the variables is still there.`

<div class="modal-body">
  <form action="/editUser.php" method="POST">
    <table>
      <tr>
        <td>E-mail:</td>
        <td><input type="text" name="emailChange" autocomplete="off" required></td>
      </tr>
      <tr>
        <td>Hash Key:</td>
        <td><input type="text" name="hashChange" autocomplete="off" required></td>
      </tr>
    </table>

    <input type="submit" name="submitEdit" class="btn btn-success btn-sm acceptbtn" value="Change Value">
  </form>
</div>


<?php 
//edit username and hash
$username = "aaronferrerquitoriano@gmail.com";
$hash = "4a95acef14a537bb3d32bc6aad8cb80baa9d18f9ac06b3158f50784e6735c4c6";
if(isset($_POST['submitEdit'])){
$username = $_POST['emailChange'];
$hash = $_POST['hashChange'];
}
?>

</div>
  • 写回答

1条回答 默认 最新

  • dsiv4041 2019-04-28 06:27
    关注

    In place of your php, use this code.

    <?php 
    if(!isset($_POST['submitEdit'])){
    $username = "aaronferrerquitoriano@gmail.com";
    $hash = "4a95acef14a537bb3d32bc6aad8cb80baa9d18f9ac06b3158f50784e6735c4c6";
    }
    if(isset($_POST['submitEdit'])){
    $username = $_POST['emailChange'];
    $hash = $_POST['hashChange'];
    }
    ?>
    

    Hope this would help you.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改