0
<?php

include 'connectMySql.php';
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT * FROM users ';


$result = mysql_query( $sql);
if(! $result)
{
  die('Could not get data: ' . mysql_error());
}

while($row = mysql_fetch_assoc($result, MYSQL_ASSOC))
{
    echo "ID       : {$row['id']}  <br> ".
         "USERNAME : {$row['username']} <br> ".
         "EMAIL    : {$row['email']} <br> ".
         "--------------------------------<br>";
} 
echo "Fetched data successfully\n";
?>

Edited by pritaeas: Fixed markdown.

4
Contributors
6
Replies
37
Views
3 Years
Discussion Span
Last Post by matrixdevuk
0

What do you mean by "select"? Do you mean click on some row in a table displayed on your page? Or do you mean you only want to select one row from the DB where username="$username"

0
$sql = 'SELECT * FROM users WHERE username="' . $username . '" LIMIT 1');

Edited by pritaeas: Added markdown.

0

i have this problem:
Undefined index: username in C:\xampp\htdocs\PhpProject2\profile.php
and when i open my project again :
YOU ARE LOGGED IN
help me!

0

You need to define the variable $username, or if it's where you do USERNAME : {$row['username']} <br /> — you might have 'username' miss-spelled in your database.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.