7 Replies - 1451 Views - Last Post: 04 May 2011 - 02:17 AM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Php login not working

Posted 04 May 2011 - 12:39 AM

This is weird, for some reason it lets me register without errors but will not let me login. here is my code.

<?php
session_start();
    if(isset($_SESSION['user']))     //This tells you if the user is logged in because $_SESSION['user'] exists
    {
      
        $db = mysql_connect('battlescnet.ipagemysql.com', 'xxxxxxxxx', 'xnxxxxxxxxxxxx*');
  
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


$db_selected = mysql_select_db("battlesc", $db);

if (!db_selected)
{

die("cant connect");

}  
              
            $user2 = $_SESSION['user'];
            $query = "Select * FROM members WHERE setname = '".$user2."'";
            $result = mysql_query($query) or die(mysql_error());
            $name2 = mysql_fetch_array($result);
            $usercolor = $name2[setnamecolor];
            $ban = $name2[ban];

        echo 'Hi ' .$usercolor;?> <?php echo "<br><a href = \"http://battlesc.net/edit_profile.php\"> edit profile?</a><br>"  ?>
        <form action="logout.php" method="post">         <input type="submit" name="Logout" value="Logout" />
    </form>
    <?php
         
    }
      
    else
    {
?>
        <html>
        <form action="validate.php" method="post">
    <p><input type="text" name="user" size = "22" style = "font-size:14px;" value="Username"/></br>
    <input type="password" name="pass" size = "22" style = "font-size:14px;" value="Password"/>
    <input type="submit" name="Login" value="Login" /> <a href="register.php">Register?</a>
         </form>
    </html>
    <?php } ?>

This post has been edited by dangmnx: 04 May 2011 - 12:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Php login not working

#2 syncupsolutions  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 04-May 11

Re: Php login not working

Posted 04 May 2011 - 01:06 AM

What does 'not letting me login' mean ? Is it providing you with an error ? Is it acting as if you have incorrect login credentials ? Try returning your SELECT query that returns whether the username exists and see if the variables are passing correctly.

$user2 = $_SESSION['user'];
     $query = "Select * FROM members WHERE setname = '".$user2."'";

           $result = mysql_query($query) or die(mysql_error());
           $name2 = mysql_fetch_array($result);
           $usercolor = $name2[setnamecolor];
           $ban = $name2[ban];



To this:


$user2 = $_SESSION['user'];
     $query = "Select * FROM members WHERE setname = '".$user2."'";
         echo $query;
           die();       
           $result = mysql_query($query) or die(mysql_error());
           $name2 = mysql_fetch_array($result);
           $usercolor = $name2[setnamecolor];
           $ban = $name2[ban];


This post has been edited by syncupsolutions: 04 May 2011 - 01:08 AM

Was This Post Helpful? 0
  • +
  • -

#3 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: Php login not working

Posted 04 May 2011 - 01:16 AM

No error meaning, the registration and everything went through, its in my phpadmin and i can see the user... but once i go to my website. it just direct me back home and nothing changes.

http://www.battlesc.net/

if you have time, try it.
Was This Post Helpful? 0
  • +
  • -

#4 syncupsolutions  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 04-May 11

Re: Php login not working

Posted 04 May 2011 - 01:45 AM

I see. Did you try to echo the SELECT query like I said ? Where is the code that redirects the user to their page on a successful login ? What page is that you originally posted ? Need some more information.
Was This Post Helpful? 0
  • +
  • -

#5 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: Php login not working

Posted 04 May 2011 - 01:50 AM

Here's the code where it lets the user know if they have successfully registered.
<?php
session_start();     //note session here
include ('connect.php'); 

$setname =  $_POST['setname'];
$password =  md5($_POST['password']);
$aka = $_POST['aka'];
$aka1 = $_POST['aka1'];
$aka2 = $_POST['aka2'];
$aka3 = $_POST['aka3'];

   $query = "Select * FROM members WHERE setname = '".$setname."'";
   $result3 = mysql_query($query) or die(mysql_error());
   $name3 = mysql_fetch_array($result3);
        $setname1 = $name3[setname];
   
   $setname2 = strtolower($setname);
   $setname3 = strtolower($setname1);
   
      if(strcmp($setname2, $setname3) != 0)
   {
      if(strcmp($password, "") != 0)
      
      {      
      
      
      if(strcmp($aka, "") != 0)
      {
         
         echo 'Congratulations <b> ' .$setname. '</b> you have Successfully registered! <br>';
         echo 'You should now be logged in. Click <a href="index.php">here</a> to continue.';
         
//do everything
$_SESSION['user'] = $setname; //ADDS THE SESSION
$date = date("d-m-y");

$query = "INSERT INTO members (date, setname, setnamecolor, password, aka, aka1, aka2, aka3)
VALUES ('".$date."', '".$setname."', '".$setnamecolor."', '".$password."', '".$aka."', '".$aka1."', '".$aka2."', '".$aka3."')";

$result = mysql_query($query) or die(mysql_error());

                  }
      else
      {
         echo 'Please fill in all fields!';
      }
      }
      else
      {
         echo 'Please enter a Password ***';
      }
   }
   else
   {
      echo 'Sorry! that username is already registered! <a href="register.php"> Please try again.</a>';
   }
   





Here's the validation code
<?php
session_start();

header('Location:http://www.battlesc.net/');        //this makes it redirect straight back to the page specified
$user = $_POST['user'];
$pass = md5($_POST['pass']);

$db = mysql_connect('battlescnet.ipagemysql.com', 'xxxxx', 'xxxxx');

if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


$db_selected = mysql_select_db("xxxx", $db);
                                                                
if (!db_selected)                                   
{

die("cant connect");

}

$query30 = "Select ban FROM members WHERE setname = '".$user."'";
$result30 = mysql_query($query30) or die(mysql_error());

$name30 = mysql_fetch_array($result30);

$ban = $name30[ban];

if($ban == 0)
{

$query = "Select password FROM members WHERE setname = '".$user."'";
$result = mysql_query($query) or die(mysql_error());

$name = mysql_fetch_array($result);

$pass1 = $name[password];

if(strcmp($pass, $pass1) == 0 && strcmp($pass, '') != 0)
{
    $_SESSION['user'] = $user;     //creates the session variable $_SESSION['user']
    $_SESSION['pass'] = $pass;    //creates the session variable $_SESSION['pass']
    echo "Congratulations " .$user. " You are successfully logged in";
   
}

else
{
    echo 'username and/or password do not match';
}
}
else
{
    echo 'you are banned';
}
?>


and yes i've tired to echo, still no errors :(
Was This Post Helpful? 0
  • +
  • -

#6 syncupsolutions  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 04-May 11

Re: Php login not working

Posted 04 May 2011 - 01:54 AM

I'm not seeing anything off the bat that would give you results like your getting. Hav you tried returning your session variables on the first page you posted ? It relies on the $_SESSION['user'] to be set get your desired results, so maybe it's not carrying over.
Was This Post Helpful? 0
  • +
  • -

#7 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: Php login not working

Posted 04 May 2011 - 01:59 AM

returning session variables? so is
$_SESSION['user']
the problem?
Was This Post Helpful? 0
  • +
  • -

#8 syncupsolutions  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 04-May 11

Re: Php login not working

Posted 04 May 2011 - 02:17 AM

In your very first post you posted the code for what I guess is index.php Your first line determines whether or not it shows the Username and Password box with the register link, or the logged users name and what not, right ? This is how it begins.

 
if(isset($_SESSION['user']))     //This tells you if the user is logged in because $_SESSION['user'] exists
{
// The rest of the code is omitted 
}



After they register, they click the link that says 'Click here to continue', which brings them back to index.php.
If the session variable is not being carried over from your register script, then the homepage will display the login form with the register link. My suggestion to you is to echo the session variables on the index page to see if they are getting passed. so in your index page, right underneath session start, try this.

foreach ($_SESSION as $key => $var) {
echo $key . ': ' . $var;
}
die();
// This will echo all session variables



If that code draws an error, just try this

echo $_SESSION['user'];
die();
//This will echo the user variable.



If you put this code in index.php, register a new user, click the 'Click here to continue link' on your register page, and then go back to index to find blank variables. Then you session variables are not passing for some reason.

This post has been edited by syncupsolutions: 04 May 2011 - 02:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1