从id值为的数据库中检索数据



这是另一个php文件的链接,指向update.php文件。我从这个链接中得到了链接的id。现在我想使用该id从数据库中检索数据,我该怎么做?

echo '<a href="update.php?id= "'.$row['id'].'">Modify</a>';

现在这是我的更新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 显示值

这是您的解决方案工作代码。

  echo '<a href="update.php?id='.$row['id'].'">Modify</a>';

用此行替换上述代码。事实上,你的错误是你在URL完成之前已经完成了",所以你的动态传递值不被视为参数,我只是删除了那个double(")。希望它能对你有所帮助。

首先检查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"; 
}

最新更新