【发布时间】:2015-10-16 01:26:39
【问题描述】:
我正在尝试使用 MySQL 数据库中的数据填充文本字段,但我的代码似乎无法正常工作。
任何帮助将不胜感激。
代码如下:
<?php include ("../config.php");
// Connect to server and select database.
mysql_select_db($db, $con);
// get value of id that sent from address bar
$id = $_GET['ID'];
// Retrieve data from database
$sql="SELECT * FROM members WHERE id='$id'";
$result=mysql_query($sql);
echo '<form name="Edit" method="post" action="update.php">
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Name:</strong></td>
<td align="center"><strong>Contact:</strong></td>
<td align="center"><strong>Division:</strong></td>
<td align="center"><strong>Rank:</strong></td>
</tr>';
while ($row = mysql_fetch_assoc($result))
{
//we will echo these into the proper fields
echo '<tr>';
echo '<td align="center"><input name="Name" type="text" id="Name" value="'; echo $row['Name']; echo '"></td>';
echo '<td align="center"><input name="Contact" type="text" id="Contact" value="'; echo $row["Contact"]; echo'" size="15"></td>';
echo'<td>
<select name="Divison">
<option value="L4D2">L4D2</option>
<option value="CSS">CSS</option>
<option value="GMOD">GMOD</option>
<option value="TF2">TF2</option>
</select>
</td>
<td>
<select name="Rank">
<option value="Division Leader">Division Leader</option>
<option value="Admin">Administrator</option>
<option value="Member">Member</option>
</select>
</td>
</tr>';
echo '<tr>';
echo '<td align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</form>';
}
echo '
</tr>
</table>
</body>
</html>';
// close connection
mysql_close();
?>
【问题讨论】: