DarkWater Posted May 2, 2008 Share Posted May 2, 2008 That's wonderful, but you sound kind of dumb correcting someone who's trying to help you in such an arrogant manner. =/ Okay, I misspelled the table. If you picked up on it, just execute the new query and post the results, no need to say "I picked that up." in such an "I told you so" way. =/ Wow. People these days. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532072 Share on other sites More sharing options...
GameYin Posted May 2, 2008 Author Share Posted May 2, 2008 I wasn't trying to be rude. I was just saying I noticed the misspell. Not trying to brag. I'm so confused I wouldn't know how . 1 gameyin // usre 3ee80237eb604ba79992f1e67b189c72 //password ryan reese //first name and last name [email protected]// email 02, 04 08 //join date...? 12.173.105.169 //ip d278e905689fe8cacf0f035f6d145639fd81c7b9//activation code 0//activationn. 0 = no 1 = yes. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532075 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 Change: $pass = mysql_real_escape_string($_POST['password']); To: $pass= md5(mysql_real_escape_string(trim($_POST['password']))); You need to check the MD5 of the password against the MD5 hash in the database. It should work now. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532080 Share on other sites More sharing options...
GameYin Posted May 2, 2008 Author Share Posted May 2, 2008 Absolutely love it. Funny, I've been coding PHP 1 year less then you. And I'm 16. Your 15. Funny huh. Guess just me. AWESOME. FINALLY FIXED! One thing though. If I enter someone's details that aren't activated. (Check last post. user=GameYin, pass=gameyin) Then it will stay on loginaction.php. Won't echo or anything. I tried doing a header back to login.php but still no luck. Even added or die mysql error. That. Not working... Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532084 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 <?php session_start(); include 'config.php'; $user = mysql_real_escape_string($_POST['username']); $pass = md5(mysql_real_escape_string(trim($_POST['password']))); if (strlen($user) > 0 && strlen($pass) >0){ $sql="SELECT * FROM Users WHERE Username = '$user' AND Password = '$pass' LIMIT 1"; echo $sql; $query = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($query); if (mysql_num_rows($query) > 0 && $row['Activated'] == 1) { $_SESSION["status"] = "Logged"; $_SESSION['username'] = $user; $_SESSION['password'] = $pass; header("Location: index.php"); exit; } else { echo "Sorry, user details not found!"; echo "<br />If you've already registered, be sure to activate your account."; echo '<br /><a href="login.php">Try again.</a>'; } else { $_SESSION["status"] = "Not logged"; $_SESSION['username'] = Guest; echo "Something went wrong"; } ?> Should Activated be set to 0 or 1 if they are activated? 1, right? I changed some things. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532094 Share on other sites More sharing options...
GameYin Posted May 2, 2008 Author Share Posted May 2, 2008 That code didn't work. Your code was a bit buggy and didn't work. You cant have two else statements. For the middle else statement I just changed it to elseif. The code that works and the one I am keeping is: <?php session_start(); include 'config.php'; $user = mysql_real_escape_string($_POST['username']); $pass = md5(mysql_real_escape_string(trim($_POST['password']))); if (strlen($user) > 0 && strlen($pass) >0){ $sql="SELECT * FROM Users WHERE Username = '$user' AND Password = '$pass' LIMIT 1"; $query = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($query); if (mysql_num_rows($query) > 0 && $row['Activated'] == 1) { $_SESSION["status"] = "Logged"; $_SESSION['username'] = $user; $_SESSION['password'] = $pass; header("Location: index.php"); exit; } elseif (mysql_num_rows($query) === 0) { echo "Sorry, user details not found or you aren't activated."; echo " If you've already registered, be sure to activate your account."; echo ' <a href="login.php">Try again.</a>'; } else { $_SESSION["status"] = "Not logged"; $_SESSION['username'] = Guest; echo "Something went wrong"; } } ?> I fixed it. Thanks for all the help guys. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532131 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 I meant to put elseif. =D I was kind of busy trying out some stuff with mod_rewrite on my server while I was helping you, so I wasn't fully paying attention. Lol. Glad I could help though. Link to comment https://forums.phpfreaks.com/topic/103719-solved-not-selecting-from-db-login/page/2/#findComment-532133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.