简体   繁体   English

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

[英]Updating the value of a variable in php code if submit button is clicked

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. 我正在做一个简单的表单,其中有两个文本框,当我输入值并单击按钮时,输入的值将被设置/更新为php代码中的变量。 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']; } ?> 

In place of your php, use this code. 代替你的php,使用此代码。

<?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. 希望这会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM