Hi
when I run my code the loop doesn't stop! which force the browser to freez.I don't know what is wrong with the loop
I have around 4 users only !
and my query select only one of them

here is my code :

    $id    = $_GET['id'];
    $sql   = "SELECT * FROM users WHERE id='".$id."'";
    $query = mysql_query($sql) or die(mysql_error());
    $check = mysql_fetch_array($query);
   if($check[0]>0) {

    while($row = $check ) {
        $username = $row['username'];
        echo $username;

}

Since you are going to fetch only one row from DB table regarding to requested id by method get, it would be more convenient to use mysql_fetch_row() function.

Also make check for your input, something like:

$id = isset($_GET['id'] && (int)($_GET['id']) !== FALSE) ? $_GET['id'] : 'exit';

if ($id === 'exit')
{
    header('Location: http://www.example.com/'); // or some predefined page in this case
    exit();
}
//rest of your code here

A small correction: you cannot compare booleans with integers, otherwise you get unexpected results. An example:

$a['foo'] = FALSE;
echo (int)$a['foo'] !== FALSE ? 'true':'false';

The problem here is given by (int). The comparison will translate to 0 !== FALSE which returns true instead of false, the same happens if the value is NULL.

commented: Thanks for clarification. +1
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.