Jump to content

[SOLVED] Not selecting from DB. Login


GameYin

Recommended Posts

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.

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.

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...

<?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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.