Jump to content

New to Php Need Help !


Deanznet

Recommended Posts

This is my php code for the login page.

 

<?

include("include/common.php");

 

if( $_POST['username'] && $_POST['password'] ){

$failed = 1;

$username = $_POST['username'];

$password = $_POST['password'];

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";

# echo $query;

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

if ( ($result) && (mysql_num_rows($result) > 0) ){

$row = mysql_fetch_object($result);

$adlogin = $row->username;

$myname = $row->username;

$adpassword = $row->password;

$myuid = $row->uid;

# echo $adlogin." ----".$adpassword."<br>";

if ( ($username != $adlogin) || ($password != $adpassword) ){

$failed = 1;

}else{

$failed = 0;

$loggedin = 1;

session_register("loggedin");

session_register("myuid");

session_register("myname");

}

}else{

$failed = 1;

}

}

if($loggedin){

ob_start();

header("Location: account.php");

}

include("include/header.php");

?>

It wont login tho... Every time i hit submit it gose back to the login page... Any idea?
Link to comment
Share on other sites

hey Deanznet,

 

when you uncomment this line  #        echo $adlogin." ----".$adpassword."

is the correct pw's returned?

 

side notes:

for security, you should never check for a pw in your query. The users's username should be a unique key your table, so you can just query for the username

 

in your statement: if ( ($username != $adlogin) || ($password != $adpassword) )

you already verified the username, so you don't need another check, this would be more efficient and cleaner style:  if ($password != $adpassword) { $failed = true

 

once you change those, try it out... if still not working, look at your session info,

here's how it should work based on what you've posted:

$failed = false;

$loggedin = true

 

@session()

$_SESSION["loggedin"] = $loggedin;

$_SESSION["myuid"] = $myuid;

$_SESSION["myname"] = $myname;

 

still not working? try it w/o the output buffer

and add an exit(); after you  call the header (again just cleaner style)

 

 

Link to comment
Share on other sites

Ya still not working and it shows the username and pw on the top... now

 

 

<?

  include("include/common.php");

 

  if( $_POST['username'] && $_POST['password'] ){

      $failed = 1;

      $username = $_POST['username'];

      $password = $_POST['password'];

      $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";

#      echo $query;

      $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

      if ( ($result) && (mysql_num_rows($result) > 0) ){

        $row = mysql_fetch_object($result);

        $adlogin = $row->username;

        $myname = $row->username;

        $adpassword = $row->password;

        $myuid = $row->uid;

      echo $adlogin." ----".$adpassword."

";

        if ( ($username != $adlogin) || ($password != $adpassword) ){

            $failed = 1;

        }else{

            $failed = 0;

            $loggedin = 1;

            session_register("loggedin");

            session_register("myuid");

            session_register("myname");

        }

      }else{

        $failed = 1;

      }

  }

  if($loggedin){

      ob_start();

      header("Location: account.php");

  }

  include("include/header.php");

?>

 

Thats what i got so far... i really dont understand the other stuff you said LOl

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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