PHP MySQL login function -
i'm using this:
function authuser($username, $password){ connectdb(); $sql = "select id, username users username = '".$username."' , password = '".$password."'"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if ($num_rows > 0){ while ($row = mysql_fetch_array($result)){ $username = $row['username']; session_start(); session_register('username'); return $username; } } closeconn(); } with combination of this:
$auth = authuser($username, $password); if (isset($username)){ header( "location: index.php" ); } and on index.php (where redirect them if successful login) i'm trying echo $username. nothing showing? ideas? function problem?
edit:
have changed so:
if ($num_rows > 0){ while ($row = mysql_fetch_array($result)){ $_session['username'] = $row['username']; return true; } } is right?
i change:
while ($row = mysql_fetch_array($result)){ $_session['username'] = $row['username']; return true; } into:
$row = mysql_fetch_array($result); $_session['username'] = $row['username']; because want login , 1 person out
Comments
Post a Comment