Reputation: 59
How do I pass id from 1st page to 2nd page?
In 1st Page I have query out my table
1st table: userdetails
userID
Username
Email
Address
NationalID
View More
In 2nd Page I need to mix 2 table into 1
2nd table: userimage
imageID
UserID
imageupload
For view more is not from my table is from this code.
<?php echo "<a href='userdetails.php?id=".$result['userID']."'>"?> View More </td>
Below is my 2nd page code
$sql = "SELECT userdetails.imageupload
FROM userdetails
INNER JOIN user ON userdetails.memberpostID = user.memberpostID";
$query = mysqli_query($db,$sql);
And this is the output on 2nd page
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
DATA OUTPUT
}
But the output always show all data from userimage
Question that I want: I wanted that if user click on "VIEW MORE" on userID 1 , it will show userID details + imageupload on my 2nd page.
Upvotes: 0
Views: 62
Reputation: 4849
You need to pass the userID
to the query.
$userID = $_GET['id'];
WRONG WAY
$sql = "SELECT userdetails.imageupload
FROM userdetails
INNER JOIN user ON userdetails.memberpostID = user.memberpostID WHERE userdetails.userID='".$userID."'";
CORRECT WAY
$sql = "SELECT userdetails.imageupload
FROM userdetails
INNER JOIN user ON userdetails.memberpostID = user.memberpostID WHERE userdetails.userID=:userID";
$query = $db->prepare($sql);
$query->execute(array(':userID' => $userID));
Note: User parameterized query to pass in the userID from the $_GET
request to prevent SQL Injection. Don't concatenate variables, instead bind the parameters.
Upvotes: 2