我有一个用于更新现有记录的小表单。从按钮点击将数据从MySQL数据库加载到HTML文本框
我使用PHP加载服务ID s到下拉框。当用户点击按钮时,应该在下面的文本框中显示与该ID相关的其他详细信息。 这是我到目前为止的代码。
<html>
<head>
</head>
<body>
<?php
//Database initialization
require_once("db_handler.php");
$conn = iniCon();
$db = selectDB($conn);
$query = "SELECT * FROM taxi_services ORDER BY SID";
$result2 = mysql_query($query, $conn);
?>
<div id="upserv">
<b id="caption2">Update location</b>
<br/><br/>
<form name="upServForm" action="<?php echo $PHP_SELF; ?>" method="post" >
<?php
$dropdown = "<select name='codes'>";
while($row = mysql_fetch_assoc($result2))
{
$dropdown .= "\r\n<option value='{$row['SID']}'>{$row['SID']}</option>";
}
$dropdown .= "\r\n</select>";
?>
Service ID <?php echo $dropdown; ?> <input type="submit" value="Load" name="loadbtn">
<table width="300" border="0">
<tr>
<td>Name</td>
<td><input type="text" name="upName" style="text-align:right" value="<? echo $savedName; ?>" /></td>
</tr>
<tr>
<td>Cost</td>
<td><input type="text" name="upCost" style="text-align:right" value="<? echo $savedCost; ?>" /></td>
</tr>
<tr>
<td>Active</td>
<td><input type="checkbox" name="upActive" value="<? echo $savedActive; ?>" /></td>
</tr>
</table>
</div>
<br/>
<div id="buttons">
<input type="reset" value="Clear" /> <input type="submit" value="Save" name="updatebtn" />
</div>
</form>
<?php
if(isset($_POST["loadbtn"]))
{
$id = $_POST["codes"];
$query = "SELECT Name, Cost, Active FROM taxi_services WHERE SID = '$id' ";
$result = mysql_query($query, $conn);
$details = mysql_fetch_array($result);
$savedName = $details["Name"];
$savedCost = $details["Cost"];
$savedActive = $details["Active"];
}
?>
</body>
</html>
该查询执行得很好,但数据没有显示在文本框中。任何人都可以告诉我我在这里失踪了什么?
谢谢。
就可以显示该数据库表结构过于 – diEcho
我觉得你的服务器不支持[短标签(http://www.php.net/manual/en/ini.core.php#ini。短的开放式标签)。换句话说,将'<?'替换为<?php' – Adi
@diEcho [here](http://i.imgur.com/9wHgG.png)。 @Adnan我也试过'',但无济于事。 – Isuru