简体   繁体   English

用来自mysql php的数据替换输入字段

[英]replace input field with data from mysql php

I created this layout of successive text input fields, 1- Enter data into empty fields 2- Click on button which submits to a php page that updates into database 我创建了这种连续文本输入字段的布局,1-将数据输入到空字段中2-单击提交到更新到数据库的php页面的按钮

Now the problem is that i want when i return to the main page again the empty field is replaced with data just added but there are still other empty fields to enter new data. 现在的问题是,我想当我再次返回主页时,将空字段替换为刚刚添加的数据,但是仍然有其他空字段可以输入新数据。 How can i establish that? 我该如何确定呢?

Thanks in advance. 提前致谢。

You haven't given a lot of detail but here goes! 您没有提供太多细节,但是这里有!

You could build your inputs like this: 您可以这样构建输入:

<input type="text" name="age"  value="<?php echo $age;  ?>">

When the form first loads, it won't have values for variables like $age, so the input will appear empty. 第一次加载表单时,它没有$ age之类的变量值,因此输入将显示为空。 Have the form submit via POST to the same PHP file, run your validation checks, and if everything passes, insert into to your database. 通过POST将表单提交到相同的PHP文件,运行验证检查,如果一切都通过,则插入到数据库中。 (Is it required that you write to the database at this point, or should it wait until the second section is filled out?) (是否需要此时写入数据库,还是应该等到第二部分填写完毕?)

You'll need to use some kind of conditional statement to display the second part of the form. 您将需要使用某种条件语句来显示表单的第二部分。 Depending on how complex this is, or whether users will be returning later, you could: 根据操作的复杂程度或用户以后是否返回,可以:

  1. Read the data back out of the database to check for completeness, and then display the second part. 从数据库中读回数据以检查完整性,然后显示第二部分。
  2. Set a variable to track what stage of the form you're in, and based on that, display different sections to be completed. 设置一个变量以跟踪您所处表单的哪个阶段,并在此基础上显示要完成的不同部分。

If you have a way of tracking what stage of the process you're in, you could do something like this: 如果您可以跟踪流程的哪个阶段,可以执行以下操作:

$formStage = 2;
function isReadOnly($formStage='')
{
    if ($formStage == 2) {echo 'READONLY';}
}

and then in your HTML: 然后在您的HTML中:

<INPUT NAME="realname" VALUE="Hi There" <?php isReadOnly($formStage)?>>

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

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