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