chanfuterboy Posted December 5, 2009 Share Posted December 5, 2009 hi, chek the code below and tell my pls what im doind wrong. <?php include("dbconfig.php"); //session_start(); // we must never forget to start the session //session_start(); if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $usernameEnc = md5($username); $password = md5($_POST['password']); require_once("dbconfig.php"); // check if the user id and password combination exist in database $query = "SELECT * FROM users WHERE usernameEnc = '$usernameEnc' AND password = '$password'"; $row = mysql_query($query) or die ("Error - Couldn't login user."); if (mysql_num_rows($row) == 1) { // the user id and password match, // set the session $_SESSION['username'] = $row['username']; $array = mysql_fetch_assoc($row); $_SESSION['username'] = $array['username']; // after login we move to the main page echo "Welcome $username! You've been successfully logged in."; echo"<p><img src='images/loading.gif'></p>"; echo "<META HTTP-EQUIV=\"Refresh\" Content=\"2; URL=members.php?user=$usernameEnc&pass=$password\">"; exit(); } else // bad info. { echo "Error - Couldn't login user.<br /><br /> Please try again."; echo"<p><img src='images/loading.gif'></p>"; echo "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=index.php\">"; exit(); } } ?> <?php if ($_GET['user']&&$_GET['pass']) { $password = $_GET['pass']; $username = $_GET['user']; $query = "SELECT username FROM users WHERE usernameEnc = '$username' AND password = '$password'"; $row = mysql_query($query) or die ("Error - Couldn't login user."); if (mysql_num_rows($row) == 1) { $array = mysql_fetch_assoc($row); $user = $array['username']; echo "<table style=\"padding-left:70px; padding-right:5px;\" width=\"100%\"><tr><td><p>Welcome, $user</p></td><td align=\"right\">"; include('menu.php'); echo "</td></tr></table>"; } else { echo "Error - Couldn't login user.<br /><br /> Please try again."; echo"<p><img src='images/loading.gif'></p>"; echo "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=index.php\">"; exit(); } } else { ?> <table width="100%"><tr><td style="padding-left:20px;"><a href="online.php">Online members</a> <a href="register.php"> Registra</a> <a href="recoverpass.php"> Forgot password?</a></td><td align="right"> <?php if($_SESSION['id']) { echo " Welcome, ".$_SESSION['username']; } else { ?> <form action="login.php" method="post"> <p align="right"><label><b>Username:</b> <input type="text" name="username" size="10" value="<?php echo $username; ?>"></label> <label><b>Password:</b> <input type="password" name="password" size="10" value="" /></label> <input type="submit" value="Login!"> </p> </form> </td></tr></table> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184085-if-else-problem/ Share on other sites More sharing options...
Raider Posted December 5, 2009 Share Posted December 5, 2009 What error are you getting? Where is it messing up? Quote Link to comment https://forums.phpfreaks.com/topic/184085-if-else-problem/#findComment-971866 Share on other sites More sharing options...
chanfuterboy Posted December 5, 2009 Author Share Posted December 5, 2009 I dont know it just post blank Quote Link to comment https://forums.phpfreaks.com/topic/184085-if-else-problem/#findComment-971867 Share on other sites More sharing options...
.josh Posted December 5, 2009 Share Posted December 5, 2009 hi, chek the code below and tell my pls what im doind wrong. Not explaining what your script is supposed to doing Not explaining what the problem is Not posting just the relevant code Writing like a 5 year old. I'm sure I can think of other things you did wrong if I try really hard. Quote Link to comment https://forums.phpfreaks.com/topic/184085-if-else-problem/#findComment-971868 Share on other sites More sharing options...
chanfuterboy Posted December 5, 2009 Author Share Posted December 5, 2009 The script is a login script, as when user is online it should post the members link. Now it post blank what can be the problem Quote Link to comment https://forums.phpfreaks.com/topic/184085-if-else-problem/#findComment-971869 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.