First Name from database in php login form -
i have login form users , admin , want users greeted there first name after login.
i have table called users following columns id
, username
, password
, admin
, fname
, lname
i have login script code below , if guys/gals can offer new php
//connect db include("conndb.php"); session_start(); //get variables login form $username = $_post['username']; $password = $_post['password']; echo $username; echo $password; $password = md5($password); //query find if user , password exist , match password. $query = "select username, admin users (username = '$username' , password = '$password')"; $result = mysql_query($query) or die (mysql_error($connect)); if (mysql_num_rows($result) !=1) { $_session['loginfail'] = 1; header ('location: index.php'); } elseif (mysql_num_rows($result) ==1) { // check admin flag $a = mysql_fetch_array($result); if ($a[admin] == y) { $_session['admin'] = 1; header('location: admin.php'); } else { $_session['user'] = $fname; header('location: index2.php'); } }
change
if ($a[admin] == y) { $_session['admin'] = 1; $_session['username'] = $a['username']; header('location: admin.php'); } else { $_session['user'] = 1; $_session['username'] = $a['username']; header('location: index2.php'); }
now use $_session['username'] show user name on web page.
Comments
Post a Comment