Jump to content

Recommended Posts

<?php session_start();

include 'Functions.php';
include 'Database.php';

$username = Clean($_POST['username']);
$password = Encrypt($_POST['password']);

if (isset($username) && isset($password)) {

$sql = "SELECT * FROM `users` WHERE username = '$username AND password = '$password'";
$results = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($results) > 0) {

header('Location:hello.php');

} else {

print "Please Enter All Field's";

}

} else {

print "Account Does Not Exist";

}
?>

 

When i only fill one field and post it it show's the "Account Does Not Exist" error,

 

it wont show any other error except the "Account Does Not Exist" one :S,

 

anyone have any idea's ?,

 

Many thanks,

 

James.

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/
Share on other sites

Sorry refix.

<?php session_start();

include 'Functions.php';
include 'Database.php';

$username = Clean($_POST['username']);
$password = Encrypt($_POST['password']);

if (isset($username) && isset($password)) {

$sql = "SELECT * FROM `users` WHERE username = '$username' AND password = '$password'";
$results = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($results) > 0) {

header('Location:hello.php');

} else {

print "Please Enter All Field's";

}

} else {

print "Account Does Not Exist";

}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853245
Share on other sites

Echo out '$_POST['username']' and '$_POST['password']' to make sure there are values being sent.  If there are, see what exactly your 'Clean' and 'Encrypt' functions return.

 

That's the only way your if wouldn't be true.

 

i used print_r() before the if statment and i got,

 

Array ( [username] => test [password] => test [submit] => Submit ) Account Does Not Exist

 

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853247
Share on other sites

Change in functions.

<?php

function Clean($value) {

if(is_array($value)) {
        if(get_magic_quotes_gpc()) {
            $value=array_map("stripslashes",$value);
            }
        if(!array_map("is_numeric",$value)) {
            $value=array_map("mysql_real_escape_string",$value);
            }
        }
    else {
        if(get_magic_quotes_gpc()) {
            $value=stripslashes($value);
            }
        if(!is_numeric($value)) {
            $value="'" . mysql_real_escape_string($value) . "'";
            }
        }
    return $value;
    }

function Encrypt($input) {

$encrypt = sha1(md5($input));

}
return $encrypt;

?>

 

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853255
Share on other sites

Which functions are you using?  You listed 2 separate ones with the same name...

 

 

Im using Encrypt() and Clean() :).

 

I know that.  But you posted 2 separate functions with those names.

 

The first set:

 

function Clean($input) {

$clean = mysql_real_escape_string(stripslashes($input));

}

function Encrypt($input) {

$encrypt = sha1(md5($input));

}
?>

 

They are the functions used in the script.

 

Problems: You don't return anything in either of these functions.

 

 

And the second set:

 

Change in functions.

function Clean($value) {

if(is_array($value)) {
        if(get_magic_quotes_gpc()) {
            $value=array_map("stripslashes",$value);
            }
        if(!array_map("is_numeric",$value)) {
            $value=array_map("mysql_real_escape_string",$value);
            }
        }
    else {
        if(get_magic_quotes_gpc()) {
            $value=stripslashes($value);
            }
        if(!is_numeric($value)) {
            $value="'" . mysql_real_escape_string($value) . "'";
            }
        }
    return $value;
    }

function Encrypt($input) {

$encrypt = sha1(md5($input));

}
return $encrypt;

?>

 

 

Problems: You are missing a terminating '}' for your 'Encrypt()' function.

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853262
Share on other sites

Also, you need to switch the two else statements.

 

The first if checks if the username and password have been supplied.  The second if checks if they match any record in the database

 

<?php session_start();

include 'Functions.php';
include 'Database.php';

$username = Clean($_POST['username']);
$password = Encrypt($_POST['password']);

if (isset($username) && isset($password)) {

$sql = "SELECT * FROM `users` WHERE username = '$username' AND password = '$password'";
$results = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($results) > 0) {

header('Location:hello.php');

} else {

print "Account Does Not Exist";

}

} else {

print "Please Enter All Field's";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853269
Share on other sites

Ok, This is the script so far as im building it.

 

<?php session_start();

include 'Functions.php';
include 'Database.php';

$username = Clean($_POST['username']);
$password = Encrypt($_POST['password']);
$sekret = Clean($_POST['sekret']);
$POST = count($_POST);
$GET = count($_GET);
$length = strlen($_POST['username'] || $_POST['password']);

if ($POST > 3 || $GET > 0) {

if ($length > 32) {

if ($_SESSION['token'] != $_POST['token']) {

echo "Invalid submission.";

exit();

}


if (isset($username) && isset($password)) {

$sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$results = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($results) > 0) {

header('Location:hello.php');

} else {

print "Submission Error, Too Man Post Varibles.";

}

} else {

print "Submission Error, Post Varibles Too Long";

}

} else {

print "Error, Account Does Not Exist";

}

} else {

print "Error, Please Enter All Field's";

}
?>

 

It is still showing the one error for everything.

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853277
Share on other sites

This is what I'm assuming you are trying to do with your code.

<?php session_start();

include 'Functions.php';
include 'Database.php';

$username = Clean($_POST['username']);
$password = Encrypt($_POST['password']);
$sekret = Clean($_POST['sekret']);
$POST = count($_POST);
$GET = count($_GET);
$length = strlen($_POST['username'] || $_POST['password']);

if ($_SESSION['token'] != $_POST['token']) {
        echo "Invalid submission.";
        exit();
}

if ($POST == 4 && $GET == 0) {

        if ($length > 32) {

                $sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
                $results = mysql_query($sql) or die (mysql_error());

                if (mysql_num_rows($results) > 0) {

                        header('Location:hello.php');

                } else {

                        print "Error, Account Does Not Exist";

                }

        } else {

                print "Submission Error, Post Varibles Too Long";

        }

} elseif ($POST < 4 && $GET == 0) {

        print "Error, Please Enter All Field's";

} else {

        print "Submission Error, Too Man Post Varibles.";

}
?>

 

I am just a little unclear on what you are trying to do with this part:

$length = strlen($_POST['username'] || $_POST['password']);

I think (I haven't tested this) this will always return a length of 1 as it is a conditional check.

Link to comment
https://forums.phpfreaks.com/topic/161714-solved-else-help/#findComment-853306
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.