我尝试使用HTML,PHP和MYSQL从数据库中提取数据并将其显示在表单中(稍后进行编辑)。在这一点上,我只是试图提取数据并以表格形式显示。 (我后来担心更新)。我拉数据但我的文本框中没有显示任何内容:
<?php
$con = mysqli_connect("XXXXX"); //removed for privacy
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query="select * from VOLUNTEER";
echo '$query';
$result = mysqli_query($con, $query);
echo "<table>";
if ($result)
{
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo '<form method = "post" action="insertvolunteer.php">';
echo '<tr>';
echo '<td>First Name:</td>';
echo '<td>' . '<input type=text name=FirstName' . $row["FirstName"] . '</td>';
echo '<td>' . '<input type=hidden name=VolunteerId' . $row["VolunteerId"] . '</td>';
echo '</tr>';
}
}
echo "</form>";
echo "</table>";
mysqli_close($con);
?>
答案 0 :(得分:2)
文本框数据需要在value
上显示为
echo '<td><input type="text" name="FirstName" value="'.$row["FirstName"].'"></td>';
答案 1 :(得分:0)
<强> connect.php 强>
<?php
$server = "server";
$user = "user";
$password = "password";
$bd = "yourbd";
$connect = mysql_connect($server, $user, $password);
$connect = mysql_select_db("$bd", $connect);
if (!$connect){
echo mysql_error(); exit;
}
?>
<强> namefile.php 强>
<?php
include('connect.php');
$select = mysql_query("select * from VOLUNTEER");
while ($show = mysql_fetch_assoc($select)):
echo "<table>";
echo "<form method = 'post' action='insertvolunteer.php'>";
echo '<tr>';
echo '<td>First Name:</td>';
echo '<td><input type="text" name="FirstName" value="'.$show["FirstName"].'"></td>';
echo '<td><input type="text" name="FirstName" value="'.$show["VolunteerId"].'"></td>';
echo '</tr>';
echo "</form";
echo "</table>";
endwhile;
?>
创建MySQL查询时,需要声明这一点。怎么样?
$ var =“SELECT * FROM SOMEWHERE”;的错强>
$ var = mysql_query(“SELECT * FROM SOMEWHERE”);的右强>
echo '<td>' . '<input type=text name=FirstName' . $row["FirstName"] . '</td>';
中的'n,您需要关闭代码。而且也不需要单独<td>
<input>
。
尝试类似的事情:)
@update 我意识到你已经得到了所希望的东西。欢呼声。