0
<?php
session_start();
$_SESSION['id']="id";
?>

<!DOCTYPE html>
<html>
<head>
    <title>Update</title>
</head>
<body>

<table border="2">
    <tr>
        <th>Username</th>
        <th>Email</th>
        <th>Edit</th>
    </tr>
<?php
     $conn=mysqli_connect("localhost","root","","telephasic");
     $q2="select * from register where id = '".$_SESSION['id']."'";
     $run=mysqli_query($conn, $q2);
     while($row=mysqli_fetch_array($run))
     {
         $name=$row[1];
         $email=$row[2];
     ?>

    <tr>
        <td><?php echo $name; ?></td>
        <td><?php echo $email; ?></td>
        <td><a href="edit.php"> Edit </a></td>
    </tr>
 <?php } ?>
 </table> 
 </body>

here i want to fetch an individual row information stored in database i can't able to fetch the data so what i have to do here for fetch code with help of session id

8
  • what error do you get ? @Arun Sharma Commented Jul 23, 2018 at 8:33
  • So you get no data in return or data just doesn't show up? Have you checked that $row[1] is valid and contains data? Commented Jul 23, 2018 at 8:33
  • 1
    why $row[1]... ? I guess u need something like $row['name']... Commented Jul 23, 2018 at 8:33
  • i did that but also not working Commented Jul 23, 2018 at 8:34
  • 1
    $_SESSION['id']="id"; what is this "id"? Commented Jul 23, 2018 at 8:47

2 Answers 2

1
<?php
session_start();
$id = $_SESSION['id'];
?>
<!DOCTYPE html>
<html>
<head>
    <title>Update</title>
</head>
<body>

<table border="2">
    <tr>
        <th>Username</th>
        <th>Email</th>
        <th>Edit</th>
    </tr>
<?php
     $conn = mysqli_connect("localhost","root","","telephasic");
     $q2 = "select * from register where id = $id ";
     $run = mysqli_query($conn, $q2);
     $row = mysqli_fetch_array($run);
?>
    <tr>
        <td><?= $row['name']; ?></td>
        <td><?= $row['email']; ?></td>
        <td><a href="edit.php"> Edit </a></td>
    </tr>
 </table> 
 </body>

skip the while part, cuz you are fetching single record.

Sign up to request clarification or add additional context in comments.

2 Comments

but it can only fetch data of 1st id only i have to fetch data of the person login
simply assign the user id in $_SESSION['id'] variable . i recommend to create session id when user login, and use that session variable. i already edited the code.
0

you have problem at the third row in code

$_SESSION['id']="id";

you set the $_SESSION['id'] to the string "id", so you will get nothing from your database cause you have no row that have id = "id" . remove this line and everything will work fine

3 Comments

but i cannot fetch the row info
use mysqli_fetch_row not mysqli_fetch_array at line 23
and put the second <tr> section inside the while loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.