Display information about a specific user
I created a login and logout form using "sessions". There are 2 users admin and a retailer. When an administrator logs in, he can see a list of retailers who have created an account on their 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 displayed page looks like this:
ID Name Email
1 retailer1 email1@gmail.com
2 retailer2 email2@gmail.com
When an admin clicks on an email message, they are redirected to a different page. ie admin_view_retailer_profile.php, which should display the details related to that particular email. Part of the code on this page
$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>";
}
Database type
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 cannot view the details of a particular letter. would appreciate if someone could tell me how this is done.
source to share
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>';
This is where my comment begins. the link you gave me is
The last part. It should be
? = Email something
; do you get instead? folio = something. I don't understand how we use email. in the link in this link. see echo instruction. This is the link we give.
href=\'admin_view_retailer_profile.php?email='.$row['email'].'\'>
second dot - if you check the link. no admin_view_retailer. The link you gave me in the comment section. So I am a bit puzzled by this. because i tested the code in my localhost. And it works. try a new echo expression. If it still doesn't work, you need to talk to your service. provider. how can I not do anything.
because the solution I gave you works great. I checked it out. if you want you can also check your local server.
new comment completed. Then enter your query if the last one is
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'");
}
source to share
One way to get information related to this specific email is to provide that email address in the URL. For example: -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, admin_view_retailer_profile.php does not know the email address that was selected So the alternate code is the 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 admin_view_retailer_profile.php is changed to admin_view_retailer_profile.php?email=email1@gmail.com
On admin_view_retailer_profile.php first check if the $ _GET ['email'] variable has been set. If it is installed, continue to query the database. For example: -
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>";
}
Be aware that the above code does not implement any security, i.e. checks if mail exists or not.
source to share