我希望能够从我的网络浏览器查看和编辑表格中包含的信息,但是我无法将当前值拉到 html 文本字段中。
任何人都可以阐明我对 php 很陌生吗?
表名:request_details
列名:id、name、email_address
我的 PHP 代码是:
<?
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
HTML 代码
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo "$row[id]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name" size="20" value="<?php echo "$row[name]"?>">
</td>
</tr>
<tr>
<td>Email Address</td>
<td>
<input type="text" name="email_address" size="40" value="<?php echo "$row[email_address]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
让它更容易一点的权利,当我使用实际 ID 而不是它工作的变量时,例如
<?
include "db.inc.php";//database connection
$order = "SELECT * FROM request_details WHERE id='19'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
上面显示,下面不显示
<?
include "db.inc.php";//database connection
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
好的,所以前提是我有两个网页,第一个显示我需要的所有信息
代码是:
<table>
<tr>
<td>
<table border="1">
<tr>
<td>Name</td>
<td>Telephone Number</td>
<td>Email Address</td>
<td>Venue</td>
<td>Event Date</td>
<td>Guests</td>
<td>Chair Cover Colour</td>
<td>Sash Colour</td>
<td>Price</td>
<td>Damage Deposit</td>
<td>Status</td>
<td>Notes</td>
</tr>
<tr>
<?
$order = "SELECT * FROM request_details";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[name]</td>");
echo ("<td>$row[telephone_number]</td>");
echo ("<td>$row[venue]</td>");
echo ("<td>$row[event_date]</td>");
echo ("<td>$row[guests]</td>");
echo ("<td>$row[cover_colour]</td>");
echo ("<td>$row[sash_colour]</td>");
echo ("<td>$row[price]</td>");
echo ("<td>$row[damage_deposit]</td>");
echo ("<td>$row[notes]</td>");
echo ("<td><a href=\"edit_form.php?id=$row[id]\">View</a></td></tr>");
}
?>
</table>
</td>
</tr>
</table>
当我点击查看时,它会将我带到以下网址:
edit_form.php?id=1
例如
edit_form.php?id=19
此页面的代码(信息未显示在文本字段中):
<table border=1>
<tr>
<td>
<table>
<?
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
<form method="post" action="edit_data.php">
<tr>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<tr>
<td>Name</td>
<td>
<input type="text" name="name" size="20" value="<?php echo $row['name']; ?>">
</td>
</tr>
<tr>
<td>Email Address</td>
<td>
<input type="text" name="email_address" size="40"
value="<?php echo $row['email_address']; ?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit" name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>