php - Create variable from data pulled from database -
i'm using mysql table called users includes fields such "userid, username, , password".
when users login, form passes "username" , "password" entries authentication.php file a
select * $tbl_name username='$myusername' , password='$mypassword
.
i want run php query create new variable equal "userid" in table "username" equals variable called $username. creates new variable such as
$_session["userid"] = $userid
how can create variable userid
data pulled.
the script lines below when checking username , password , creating session variables them:
$sql="select * $tbl_name username='$myusername' , password='$mypassword'"; $result=mysql_query($sql); // mysql_num_row counting table row $count=mysql_num_rows($result); // if result matched $myusername , $mypassword, table row must 1 row if($count==1){ echo "welcome "; echo $myusername; echo "!"; // create session vars $myusername, $mypassword , redirect file "success.php" $_session["myusername"] = $myusername; $_session["mypassword"] = $mypassword; } else { echo "wrong username or password"; }
for need iterate through result in while loop. mysql_fetch_array this. following code create session object.
$result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo $row['userid']; }
Comments
Post a Comment