【问题标题】:values not being set from database information不是从数据库信息中设置的值
【发布时间】:2013-07-29 13:38:12
【问题描述】:

为什么当我加载页面时,信息不会加载到字段中?它为我提供了数据库中正确数量的行,但没有显示任何实际信息,甚至没有设置为值

<?php 

$link = mysqli_connect("localhost", "root", "", "test") or die("could not connect");

if (isset($_POST['submit']) && $_POST['submit'] == 'update') {

$updateQuery = (" UPDATE `test1` SET f_name = '$_POST[f_name]', l_name='$_POST[l_name]', email='$_POST[email]' WHERE id='$_POST[id]'");
mysqli_query($link, $updateQuery);


};


$query = ("SELECT * FROM `test1`");
$result = mysqli_query($link, $query);

echo "<table border=1
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th> 
</tr>";

while($row = mysqli_fetch_array($result)) {
?>
<form method="post" action="update.php">
<tr>
<td><input type="text" name="f_name" value="<?php $row['f_name'] ?>" ></td>
<td><input type="text" name="l_name" value="<?php $row['l_name'] ?>"></td>
<td><input type="text" name="email" value="<?php  $row['email'] ?>"></td>
<td><input type="hidden" name="id" value="<?php  $row['id']  ?>"></td>
<td><input type="submit" name="submit" value="update" ></td>
</tr>
</form>
<?php
}
?>

【问题讨论】:

  • 我如何复制你的代码,首先我回答了这个问题。

标签: php html mysql mysqli


【解决方案1】:

您没有在此处打印结果,因此它没有显示值。

<td><input type="text" name="f_name" value="<?php echo $row['f_name']; ?>" ></td>
<td><input type="text" name="l_name" value="<?php echo $row['l_name']; ?>"></td>
<td><input type="text" name="email" value="<?php  echo $row['email']; ?>"></td>
<td><input type="hidden" name="id" value="<?php  echo $row['id'];  ?>"></td>

【讨论】:

    【解决方案2】:

    你忘了 echo 使用下面的

        <td><input type="text" name="f_name" value="<?php echo $row['f_name'] ?>" ></td>
    <td><input type="text" name="l_name" value="<?php echo $row['l_name'] ?>"></td>
    <td><input type="text" name="email" value="<?php echo  $row['email'] ?>"></td>
    <td><input type="hidden" name="id" value="<?php  echo $row['id']  ?>"></td>
    

    【讨论】:

      【解决方案3】:

      使用&lt;?php echo $row['f_name']; ?&gt;&lt;?=$row['f_name']?&gt; 代替&lt;?php echo $row['f_name']; ?&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-31
        • 1970-01-01
        • 2011-03-15
        相关资源
        最近更新 更多