Ok, so I basically have a form where users can fill out information, on form submission the information gets loaded into my SQL database.
There is an "administrator" page that displays all users that are in my User Table in my DB.
All is well and good that all works perfectly but my problem is that I made the userId's clickable so that when I click on the userId that specific entry will be loaded from the db.
I can't get the userId that I selected printed on the screen.
Here's my Admin page:
<html>
<head>
</head>
<body>
<?php
//Step 1: Set the connection object equal to our database
$conn = mysql_connect("localhost", "root", "") or die (mysql_error());
//Step 2: Set the databse you want to use
mysql_select_db("assignment_3", $conn);
//Step 3: Write sql that we want to run against the database
$sql = "select id, firstName, lastName, emailAddress from usertable";
//Step 4: Run the sql statement against the database connection object we created $conn
$result = mysql_query($sql, $conn) or die (mysql_error());
//STEP 5: Process the result set $result
print "<table border='1'>";
print "<tr>";
print "<td>id</td>";
print "<td>firstName</td>";
print "<td>lastName</td>";
print "<td>emailAddress</td>";
while ($row = mysql_fetch_assoc($result)) { // this is getting each row that was returned
$clickId = $row['id'];
print "<tr>";
print "<td><a href ='showUser.php?userId=$clickId'> $clickId </a></td>";
print "<td>$row[firstName]</td>";
print "<td>$row[lastName]</td>";
print "<td>$row[emailAddress]</td>";
}
print "</table>";
?>
</body>
</html>
If you run this page all the users in the db are loaded and displayed in a table and all of their userId's become clickable links when clicked take you to the showUser.php page which displays the information for the user that was selected.
Here is the code for the showUser.php page. I need to grab the userId with the GET method from the URL and then query the DB against that ID so show the user information.
I'm really stuck and need some help.
<html>
<head>
</head>
<body>
<?php
$id = filter_input(INPUT_GET, "userId");
//Make db connection
$conn=mysql_connect("localhost","root","")or die(mysql_error());
//Step 2: select your db to use
mysql_select_db("assignment_3",$conn);
//Step 3: Write the sql that we want to run against the database
$sql = mysql_query("select id, firstName, lastName, emailAddress, phoneNumber, underGradSchoolId, gradSchoolId, securityQuestionId from usertable where id='$id'");
$result = mysql_query($sql,$conn)or die(mysql_error());
print "<table border='1'>";
print "<tr>";
print "<td>id</td>";
print "<td>firstName</td>";
print "<td>lastName</td>";
print "<td>emailAddress</td>";
print "<tr>";
print "<td>id</td>";
print "<td>firstName</td>";
print "<td>lastName</td>";
print "<td>emailAddress</td>";
print "<td>phoneNumber</td>";
print "<td>underGradSchoolId</td>";
print "<td>gradSchoolId</td>";
print "<td>securityQuestionId</td>";
print "</table>";
?>
</body>
</html>