0

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");   
             }
2
Contributors
5
Replies
8
Views
4 Years
Discussion Span
Last Post by pritaeas
1

why cant i do this?

$row = mysql_fetch_assoc($sql);

Should work just fine. No need for the while.

0

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.

0

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

thanks

0

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.

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.