Jump to content

My Login Script


forumnz

Recommended Posts

Oh dear. Running into problems today...

 

How is this wrong?

 

if(count($_POST)>0)
{
           $username=$_POST["username"];
           $password=$_POST["password"];
	   $password=md5($password);
           $sql="SELECT * FROM members
                    WHERE
                    username=\"$username\" 
                    AND 
                    password=\"$password\"";
            $rs=mysql_query($sql);               //execute the query
            if(mysql_num_rows($rs)==1) {
                    echo "Well done!";
            } 
            else{
                   //invalid username of password
                  //redirect to login page
                  header("Location: login.php");
            }
}

 

Thanks,

Sam.

Link to comment
https://forums.phpfreaks.com/topic/70276-my-login-script/
Share on other sites

it doesnt log you in because you are telling it else redirect to login.php if successful.

 

 

try

 

<?php

}else{

if(mysql_num_rows($rs)==0) {

//invalid username of password
                  //redirect to login page
                  header("Location: login.php"); } ?>

Link to comment
https://forums.phpfreaks.com/topic/70276-my-login-script/#findComment-352945
Share on other sites

Ok then.

 

Right, what should I do then. This is the current code below. I get error : Parse error: syntax error, unexpected $end in /usr/local/www/vhosts/bidbuddy.co.nz/httpdocs/login2.php on line 37

 

if(count($_POST)>0)
{
           $username=$_POST["username"];
           $password=$_POST["password"];
	   $password=md5($password);
           $sql="SELECT * FROM members
                    WHERE
                    username=\"$username\" 
                    AND 
                    password=\"$password\"";
            $rs=mysql_query($sql);               //execute the query
            if(mysql_num_rows($rs)==1) {
                    echo "Well done!";
            }else{

if(mysql_num_rows($rs)==0) {

//invalid username of password
                  //redirect to login page
                  header("Location: login.php"); }

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/70276-my-login-script/#findComment-352951
Share on other sites

were missing a closing bracket tell me what you get now:

 

<?php
if(count($_POST)>0)
{
           $username=$_POST["username"];
           $password=$_POST["password"];
	   $password=md5($password);
           $sql="SELECT * FROM members
                    WHERE
                    username=\"$username\" 
                    AND 
                    password=\"$password\"";
            $rs=mysql_query($sql);               //execute the query
            if(mysql_num_rows($rs)==1) {
                    echo "Well done!";
            }else{

if(mysql_num_rows($rs)==0) {

//invalid username of password
                  //redirect to login page
                  header("Location: login.php"); }
    }
?>

Link to comment
https://forums.phpfreaks.com/topic/70276-my-login-script/#findComment-352954
Share on other sites

<?php
if(count($_POST)>0)
{
           $username=$_POST["username"];
           $password=$_POST["password"];
	   $password=md5($password);
           $sql="SELECT * FROM members
                    WHERE
                    username=\"$username\" 
                    AND 
                    password=\"$password\"";
            $rs=mysql_query($sql);               //execute the query
            if(mysql_num_rows($rs)==1) {
                    echo "Well done!";
            }else{

if(mysql_num_rows($rs)==0) {

//invalid username of password
                  //redirect to login page
                  header("Location: login.php"); }
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/70276-my-login-script/#findComment-352959
Share on other sites

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.