我为你做了一个很好的流程图,因为这有点复杂。
基本上,我想要一个来自数据库列的字段列表,显示在一个表中。它们旁边有一个 EDIT 按钮,当您单击编辑按钮时,您可以编辑该字段。然后单击提交,它会使用新值更改表。
我几乎知道如何做每一件单独的事情,但我无法将所有这些事情合二为一。
流程图:
代码:
步骤1:
<table>
<th>First Name</th>
<?php
// Collects data from "users" table
$data = mysql_query("SELECT * FROM users")
or die(mysql_error());
// array
$info = mysql_fetch_array( $data );
// print data
// Print out the contents of the entry
Print "<tr><td>";
Print "".$info['fname'] . " ";
Print "</td><td>";
Print "".$info['lname'] . " ";
Print "</td><td>";
Print "".$info['email'] . " <br>";
Print "</td></tr>";
// loop for each row in the column
while($info = mysql_fetch_array( $data ))
{
Print "".$info['fname'] . " ";
Print "</td><td>";
Print "".$info['lname'] . " ";
Print "</td><td>";
Print "".$info['email'] . " <br>";
Print "</td></tr>";
}
?>
</table>
第 2 步和第 3 步:(不完整或可能也不准确)
<?php
if(isset($_POST['submit'])){
$variable = "somethinghere";
$variable = "somethinghere";
$variable = "somethinghere";
$variable = "somethinghere";
$variable = "somethinghere";
$query = "UPDATE users
SET fname='$variable1'
WHERE $variable2='$variable3' AND $variable4='$variable5'
(fname, lname, email) VALUES ('".$_POST['fname']."', '".$_POST['lname']."', '".$_POST['email']."')";
mysql_query($query);
}else{
?>
<div class="content">
<form method="post">
<div><strong>First Name:</strong><span class="errortext">*</span></div>
<div><input name="fname" type="text" /></div>
<div><strong>Last Name:</strong><span class="errortext">*</span></div>
<div><input name="lname" type="text" /></div>
<div><strong>Email:</strong><span class="errortext">*</span></div>
<div><input name="email" type="text" /></div>
<div><input id="submit-button" value="submit" name="submit" type="submit" /></div>
</form>
<?php }?>
</div>