<?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";
?>

i want to select the row where username="$username"

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"

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

Use LIMIT1 in your SQL statment

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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.