I have made a login and logout form using "sessions". There are 2 users admin and retailer. When the admin is logged in he is able to see a list of retailers who have created an account on his website.
I have displayed the list using the following code
<?php
con=mysqli_connect("abc.com","abc","abc","abc");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM retailerregister");
echo "<table id='admin'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td><a href='admin_view_retailer_profile.php'>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
The page that is displayed looks like this
ID Name Email
1 retailer1 email1@gmail.com
2 retailer2 email2@gmail.com
When admin clicks on an email it gets redirected to another page i.e admin_view_retailer_profile.php that should display the details that are related to that particular email. Part of the Code on this page is
$result = mysqli_query($con,"SELECT * FROM retailerregister where email='email'");
while($row = mysqli_fetch_array($result))
{
echo "Name: " . $row['name'] . "<br>";
echo "Email: " . $row['email'] . "<br>";
echo "Phoneno: " . $row['phoneno'] . "<br>";
echo "Country: " . $row['country'] . "<br>";
echo "Street: " . $row['street'] . "<br>";
echo "City: " . $row['city'] . "<br>";
echo "State: " . $row['state'] . "<br>";
echo "Zipcode: " . $row['zipcode'] . "<br>";
}
View of the Database
id name email password phoneno country street city state zipcode
1 retailer1 email1@gmail.com email1 phoneno1 country1 street1 city1 state1 zipcode1
2 retailer2 email2@gmail.com email2 phoneno2 country2 street2 city2 state2 zipcode2
The problem is that i am not able to view the details of the particular email. would appreciate if someone could tell me how it is done
Replace this line
echo "<td><a href='admin_view_retailer_profile.php'>" . $row['email'] . "</td>";
To
echo '<td><a href=\'admin_view_retailer_profile.php?email='.$row['email'].'\'>'.$row['email']. '</td>';
From here my comment start. link which you gave it me is this
The last portion. It should be
?email=something
; instead you are getting ?folio=something. i dont understand as we are using email. in the link in this link. see the echo statement. This is the link we are giving.
href=\'admin_view_retailer_profile.php?email='.$row['email'].'\'>
second point is if you check the link. there is no admin_view_retailer. The link which you gave me in the comment section. So i am bit puzzled by this. because i tested the code in my localhost. And it work. try the new echo statement. If it still does not work you need to speak with your service. provider. as i cant do any thing.
because the solution which i gave you work fine. I checked it. if you want you can check on your local server as well.
new comment finish now. Than bring your query in if statment the last one
if(isset($_GET['email']))
{
$email=$_GET['email'];
//change this line in your query as well
$result = mysqli_query($con,"SELECT * FROM retailerregister where email='email'");
//To
$result = mysqli_query($con,"SELECT * FROM retailerregister where email='$email'");
}
One of the ways in order to fetch details related to that specific email is to provide that email through URL. For Eg:-Look at your code below
<?php
con=mysqli_connect("abc.com","abc","abc","abc");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM retailerregister");
echo "<table id='admin'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td><a href='admin_view_retailer_profile.php'>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
In the above code the admin_view_retailer_profile.php does not knows the email that was fetch So an altervative is the given code below.
echo "<table id='admin'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td><a href='admin_view_retailer_profile.php?email=<?php echo $row['email'];?>'>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
Now the admin_view_retailer_profile.php changes to admin_view_retailer_profile.php?email=email1@gmail.com
On the admin_view_retailer_profile.php first check whether the $_GET['email'] variable has been set.If it is set then continue with querying the database. For Eg:-
if(isset($_GET['email'])){
$email = $_GET['email'];
$result = mysqli_query($con,"SELECT * FROM retailerregister where email={$email}");
while($row = mysqli_fetch_array($result))
{
echo "Name: " . $row['name'] . "<br>";
}
Do mind that the above code does not implement any security i.e, checking whether a email exists or not.