Mysqli to display link to profile page

Peter Gilbertson :

I'm looking for the best way for a user to be able to click on a link displayed on each row from mysql results page which will take them to a page which displays all the with regards to the id from that row.

HTML TABLE

<?php

$sql = "SELECT firstName, lastName, id FROM users";
$result = $conn->query($sql);

echo "<table border='1px'>";
echo "<tr><th>First Name</th><th>Last Name</th><th>Link</th></tr>";

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

echo "<tr>
<td>{$row['firstName']}</td>
<td>{$row['lastName']}</td>
<td> LINK HERE </td>
</tr>";

    }
} else {
    echo "0 results";
}

    echo "</table>";
?>

USER PAGE

$sql = "SELECT firstName, lastName FROM users WHERE id="????";
$result = $conn->query($sql);
Jay Blanchard :

You can pass the information in the URL query string:

http://www.example.con/user.html?id=123456

Where the '123456' is the ID in the database for the user. This will be available in the GET array;

$_GET['id']

So now you can use that variable in your query to get the user's info for the page

Warning Little Bobby says your script is at risk for SQL Injection Attacks.. Even escaping the string is not safe!

EDIT

I also noticed that you had this:

<td> LINK HERE </td>

Here is how your link would look:

<td><a href=\"user.html?id=" . $row['id'] . "\">link text</a></td> 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=21281&siteId=1