How to not clear input fields in php form?

2019-08-23 11:04发布

I have a webpage that uses php and has a bunch of input fields in which a user enters some data and I turn the input into an SQL statement to query some database. I successfully parse the input fields and put the SQL statement together but when they click the "submit" button, all the input fields get cleared. How can I make it so these input fields don't get erase every time the user clicks "submit"?

标签: php html sql input
7条回答
forever°为你锁心
2楼-- · 2019-08-23 11:41

Store them in local variables like

<?php
$name = '';
$last = '';

if(isset($_POST['post_me'])) {
   $name = $_POST['post_me'];
   $last = $_POST['last'];
   //Process further
}
?>
<form method="post">
  <input type="text" name="name" value="<?php echo $name; ?>" />
  <input type="text" name="last" value="<?php echo $last; ?>" />
  <input type="submit" name="post_me" />
</form>
查看更多
登录 后发表回答