this part is i am un sure what its doing.

while($row = mysql_fetch_array($sql))
    {
        $id = $row["id"];
    }

why cant i do this?

$row = mysql_fetch_assoc($item_query);
$id = $row['id'];

this is my login in script.
full code

//BINARY for case sensitive
$sql = mysql_query("SELECT user_id FROM user WHERE user_name='$username_p' AND BINARY password='$password_p'");

            //make sure person exists in database---
            $existCount = mysql_num_rows($sql); //count the rows where the sql is ture 
            if($existCount == 1)                //make sure name is only one in database
            {
                while($row = mysql_fetch_array($sql))
                {
                    $id = $row["id"];
                }
                    //cookies doesnt get destory when window is close
                    setcookie("id", $id, time()+172800); 
                    setcookie("username", $username_p, time()+172800); //seconds - 2 days 
                    header("location: ../index.php");   
             }

why cant i do this?

$row = mysql_fetch_assoc($sql);

Should work just fine. No need for the while.

ah i c.
also there is no need for this statment:

 $existCount = mysql_num_rows($sql);
if($existCoun==1)

bc on register.php i can make sure, there are no same user names. so in database all the names has to be different.

ah this make scence. i am not sure why alot of tutorial of login script have thoses two things in it.

thanks

i am not sure why alot of tutorial of login script have thoses two things in it.

Because the database side of those scripts are usually created ad-hoc, without much thought. They don't contain FK's, (unique) indexes, stored procedures or triggers either.

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.