0

I'm trying to do a PHP connection script, with form and data processing in the same page, but when I try my code I always get 2 errors :

Notice: Undefined index: password in C:\Users\Simon\Documents\Site FTM\connexion.php on line >7

Fatal error: Call to a member function fetch() on a non-object in C:\Users\Simon\Documents\Site FTM\connexion.php on line 18

I understand that PHP don't find the index called 'password' in $_POST, but I'm sure that the form is leading to the same page (#)... Can somebosy help me ? Here is the whole code, on PasteBin : http://pastebin.com/A9z1HHvf

Sorry, the error messages are in french, but all the other variable names are in english. You just need to know that $errDisplay is use to store all my custom error messages and display them at the bottom ofmy page.

1
  • And what does your code look like? Especially line 18... Commented Sep 29, 2013 at 17:36

2 Answers 2

4

This line is problematic:

$isFormOK = isset($_POST['username']) AND isset($_POST['password']);

AND has lower precedence than =, that's why this line reads like this:

( $isFormOK = isset($_POST['username']) )
  AND isset($_POST['password']);

In other words, whether or not $_POST['password'] is in the script, it works the same way - setting $isFormOk value based only on $_POST['username'] existence.

What you should do instead is either use && form of boolean and (it has higher precedence than =):

$isFormOK = isset($_POST['username']) && isset($_POST['password']);

... or, even better, just use the fact that isset can take more than one argument:

$isFormOK = isset($_POST['username'], $_POST['password']);

Quoting the doc:

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

Sign up to request clarification or add additional context in comments.

Comments

-1
if(isset($_REQUEST['password'])){
$pass = $_REQUEST['password'];
}

Now You can use $pass as it contains the values which is being posted.

1 Comment

The OP's code already references $_POST['password'] - all $_REQUEST does is take both GET and POST

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.