好的,我想在文本框中显示我的一个客户记录中的一个姓氏,因为我希望用户能够编辑sql数据库中存储的客户的值。我一直在尝试执行此操作,但似乎无法使它正常工作,因为它仅显示一个空框。这就是我想要做的
<FORM NAME ="form2" METHOD ="POST" ACTION = "phptest.php">
<div class="form-group">
<label for="txtForename">Forename:</label>
<input type="text" class="form-control" id="txtForename2" NAME = "txtForename" value = "<?php
$conn = mysqli_connect("localhost", "root", "", "cardatabase");
$sql = "SELECT forename FROM customers where customerID = 13";
$result = $conn->query($sql);
echo " $result";
?>">
</div>
我正在尝试在文本框的value选项中显示它,但似乎无法正常工作。注意:这是针对大学项目的,所以我对这些东西并不陌生,并且我也知道注入攻击。
预先感谢
答案 0 :(得分:1)
<?php
$conn = mysqli_connect("localhost", "root", "", "cardatabase");
$queryString= "SELECT `forename` FROM `customers` where `customerID` = '13'";
$result =mysqli_query($conn, $queryString);
if (mysqli_num_rows($result ))
{
while ($row = mysqli_fetch_assoc($result )) {
$arr[] = $row;
}
$forename = $arr[0]['forename'];
} else {
$forename = "No data found";
}
?>
<FORM NAME ="form2" METHOD ="POST" ACTION = "phptest.php">
<div class="form-group">
<label for="txtForename">Forename:</label>
<input type="text" class="form-control" id="txtForename2" NAME = "txtForename" value = "<?=$forename?>">
</div>
</form>