Pittz Pittz - 1 year ago 63
PHP Question

Retrieve data from database with id value

This is a link from another php file which directs to update.php file. I got the id of the link from this link. Now i want to use that id to retrieve data from database how can i do that?

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

Now This is my update.php file

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'];

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";

Now I want to retrieve the data from data base having id= the id value that i have got from the link so that i can display the value according to id

Answer Source

here is your solution working code is.

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

Replace above code with this line. Actually your mistake is you have completed " before URL completed so your dynamically passed value is not consider as parameter i just remove that double ("). hope it will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download