这是另一个指向update.php文件的php文件的链接。我从这个链接获得了链接的ID。现在我想使用该id从数据库中检索数据我该怎么做?
echo '<a href="update.php?id= "'.$row['id'].'">Modify</a>';
现在这是我的update.php文件
echo "<form method=\"POST\" action=\"\">\n";
include_once 'dbconnect.php';
$id= $_GET['id'];
$query = "SELECT * FROM promoter where id=$id ";// this code is not retrieving value from database
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ $user_id=$row['user_id'];
$full_name=$row['full_name'];
$qualification=$row['qualification'];
$locality=$row['locality'];
$description=$row['description'];
}
echo "<td>User Id</td><td> <input type=\"text\" name=\"user_id\" value=\"$user_id\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Full Name</td><td> <input type=\"text\" name=\"full_name\" value=\" $full_name\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Qualification</td><td> <input type=\"text\" name=\"qualification\" value=\" $qualification\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Locality</td><td> <input type=\"text\" name=\"locality\" value=\" $locality\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Description</td><td> <input type=\"text\" name=\"description\" value=\" $description\"></td>\n";
echo "</tr>\n";
echo "</form>\n";
现在我想从数据库中检索数据,其中id =我从链接获得的id值,以便我可以根据id显示值
答案 0 :(得分:1)
首先你检查id检索到update.php检查。
echo $id;
如果显示,则必须检查是否使用SQL查询从数据库中检索任何值。
print_r($result);
用下面的代码替换
echo "<form>\n";
include_once 'dbconnect.php';
$id= $_GET['id'];
$query = "SELECT * FROM promoter WHERE id='$id'";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result))
{
$user_id=$row['user_id'];
$full_name=$row['full_name'];
$qualification=$row['qualification'];
$locality=$row['locality'];
$description=$row['description'];
echo "<td>User Id</td><td> <input type=\"text\" name=\"user_id\" value=\"$user_id\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Full Name</td><td> <input type=\"text\" name=\"full_name\" value=\" $full_name\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Qualification</td><td> <input type=\"text\" name=\"qualification\" value=\" $qualification\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Locality</td><td> <input type=\"text\" name=\"locality\" value=\" $locality\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Description</td><td> <input type=\"text\" name=\"description\" value=\" $description\"></td>\n";
echo "</tr>\n";
echo "</form>\n";
}
答案 1 :(得分:1)
这是您的解决方案工作代码是。
echo '<a href="update.php?id='.$row['id'].'">Modify</a>';
用此行替换上面的代码。实际上你的错误是你在URL完成之前已经完成了“,所以你的动态传递的值不被视为参数我只是删除那个双("
)。希望它能帮到你。