是否可以从数据库中检索值并将其用作当前表单中的值?例如,我有一个带有字段" family"这是一个文本框,可以用表中的值填充该字段" EOI_AC_Data"从行" family_name"?。有人能告诉我这是怎么可能的吗?这是我目前的代码:
<?php
$conn = mysqli_connect("localhost", "twa312", "dam6av9a");
mysqli_select_db(twa312, $conn)
or die ('Database not found ' . mysqli_error() );
$sql = "SELECT * FROM EOI_AC_Data";
$rs = mysqli_query($sql, $conn)
or die ('Problem with query' . mysqli_error());
?>
<form name="eoiform" method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>" id="eoi">
<b>Student's Family Name</b>
<br>
<input type="text" id="family" name="family" />
</form>
答案 0 :(得分:2)
$row = mysql_fetch_array($rs); //fetches the row that was retrieved from the query;
//Check that $row actually contains something of course
然后在html中
<input type="text" id="family" name="family" value="<?php echo $row["whatever_your_table_field_name_is"];?>">
考虑使用mysqli_函数,因为mysql_是折旧的
答案 1 :(得分:-1)
是这样的:
<input type="text" id="family" name="family" value="<?php $valuefromdatabase; ?" />