如何让表单输入中的值等于从我的数据库中获取的数据。当我试图从后超级全局检索值时,我得到了数组([john_doe] =>),即空值
<?php print_r($_POST); ?>
<form action="" method="post">
<?php while($subs = mysqli_fetch_assoc($result)) { ?>
<input type="" name="john_doe" value='<?php echo $subs["menu_name"]; ?>'>
<input type="submit" value="sumbit">
<?php } ?>
</form>
答案 0 :(得分:0)
您的数据库提取会出现问题,您可以尝试使用以下代码
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "**YOUR QUERY**";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
<input type="text" name="john_doe" value='<?php echo $row["menu_name"] ;?>'>
<input type="submit" value="sumbit">
$conn->close();
?>