dachshund Posted August 16, 2009 Share Posted August 16, 2009 hey, simple question really. i have this log in form <?php if(!$_POST['submit'] == 'login'){ echo "<div id=\"blanket\" style=\"display:none;\"></div>\n"; echo "<div id=\"popUpDiv\" style=\"display:none;\">\n"; echo "<div id=\"close\">\n"; echo "<a href=\"#\" onclick=\"popup('popUpDiv')\">\n"; echo "<img src=\"/phptesting/images/login/close.png\">\n"; echo "</a>\n"; echo "</div>\n"; echo "<div id=\"loginform\">\n"; echo "<form name=\"login\" method=\"post\" action=\"/phptesting/account/index.php?\n"; echo $rows['id']; echo "\">\n"; echo "<span class=\"loginformtext\">Username</span>\n"; echo "<input name=\"username\" type=\"text\" class=\"loginformtext\" id=\"username\" size=\"28\">\n"; echo "<br>\n"; echo "<span class=\"passwordformtext\">Password</span>\n"; echo "<input name=\"password\" type=\"password\" class=\"loginformtext\" id=\"password\" size=\"28\">\n"; echo "<br><br>\n"; echo "<div align=\"left\"\n"; echo "<input type=\"submit\" name=\"submit\" class=\"loginformtext\" value=\"Submit\">\n"; echo "</div>\n"; echo "</div>\n"; echo "</form>\n"; echo "</div>\n"; echo "<span class=\"login_text\"><a href=\"#\" onclick=\"popup('popUpDiv')\">LOG IN</a> |\n"; }else { $user= $_POST['username']; $pass= $_POST['password']; if($user && $pass){ $sql = "SELECT * FROM `users` WHERE `username`='$user'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1){ $epass = md5($password); $sql2 = "SELECT * FROM `users` WHERE `username` ='$user' AND `password`='$epass'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) ==1){ //success $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; echo "<span class=\"login_text\"><a href=\"/phptesting/account/\">ACCOUNT</a> | <a href=\"logout.php\">LOGOUT</a></span>\n"; }else { echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n"; } }else { echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n"; } }else { echo "<span class=\"login_text\">PLEASE SUPPLY ALL VALID FIELDS | <a href=\"/phptesting\">HOME</a></span>\n"; } } ?> and then when they go to their accounts page i have <?php if($session_name){ echo "Welcome to your account.\n"; } else { echo "You are not logged in. Please log in to view your account.\n"; } ?> all i want to add is something like echo "Welcome to your account.\n"; echo $username; any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 16, 2009 Share Posted August 16, 2009 if($_SESSION['uid']){ $userid = $_SESSION['uid']; $query = "SELECT username FROM users WHERE userid = '$userid'"; $result = mysql_query($query); list($username) = mysql_fetch_row($result); echo "Welcome. \n"; echo $username; }else{ Change it to your table settings Quote Link to comment Share on other sites More sharing options...
dachshund Posted August 16, 2009 Author Share Posted August 16, 2009 cheers! Quote Link to comment Share on other sites More sharing options...
dachshund Posted August 16, 2009 Author Share Posted August 16, 2009 oh actually, is there a way that I can change it to $query = "SELECT * FROM users WHERE userid = '$userid'"; so that i can then echo something like $rows['email'] thanks! Quote Link to comment Share on other sites More sharing options...
dachshund Posted August 16, 2009 Author Share Posted August 16, 2009 will post as new question Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.