如何在PHP表单中不清除输入字段? [英] How to not clear input fields in php form?

查看:165
本文介绍了如何在PHP表单中不清除输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用php的网页,并有一大堆用户输入数据的输入字段,并将输入转换为SQL语句来查询某个数据库。我成功解析了输入字段并将SQL语句放在一起,但是当他们单击提交按钮时,所有输入字段都被清除。我怎样才能让它在每次用户点击提交时都不会被擦除?

在像

这样的局部变量中使用

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

if(isset($ _ POST ['post_me'])){
$ name = $ _POST ['post_me'];
$ last = $ _POST ['last'];
//进一步处理
}
?>
< form method =post>
< input type =textname =namevalue =<?php echo $ name;?> />
< input type =textname =lastvalue =<?php echo $ last;?> />
< input type =submitname =post_me/>
< / form>


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"?

解决方案

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>

这篇关于如何在PHP表单中不清除输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆