-3

this is someone else's code and seems to work for everyone online but me. It doesn't seem to detect the capital letters even though i have dedicated code for it.

Could someone spot the error in my code:

<?php

if($_POST['submit']){


    if(!$_POST['email']) $error.="<br />Please enter your email";
        else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid mail";

    if(!$_POST['password']) $error.="<br />Please enter your password";
    else {

            if(strlen($_POST['password'])<8) $error.="<br />Please enter a password with atleast 8 characters";
            if(!preg_match('/[A-Z]/', $_post['password'])) $error.="<br />Please enter atleast one capital letter";
        }

        if($error) echo "There were error(s) in your details:".$error;

    }   

?>




<form method="post">

        <input type="email" name="email" id="email" />
        <input type="password" name="password" />
        <input type="submit" name="submit" value="signup" />

</form>

Here is the link to it:

http://hassannasir.co.uk/mysql/

1 Answers1

5

PHP variables are case-sensitive. $_POST and $_post are two ENTIRELY different variables.

If you had error_reporting and display_errors enabled, you'd have been told about $_post being both undefined, and undefined index while using the undefined variable.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Ahhhh. Why do i always miss out the most obvious. Thanks! – Hassan Nasir Aug 26 '16 at 20:49
  • 2
    turn on those settings. they should never be off on a debug/devel system in the first place. – Marc B Aug 26 '16 at 20:49
  • I added : ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); As well as a php.ini file with: display_errors = on. But now for some reason it keeps saying "Undefined index: submit on line 7". Submit has been defined in the html. Also its not picking up any other errors. Sorry I'm new and trying really hard to learn this. – Hassan Nasir Aug 26 '16 at 21:03
  • 1
    `submit` is only defined in the html for a POST request, not the GET request to initially request the form – Mark Baker Aug 26 '16 at 21:11
  • @HassanNasir Instead of `if($_POST['submit']){` you need `if(isset($_POST['submit'])){`. As it is you're evaluating that `$_POST` index as a boolean, but as Mark said, it's undefined until you submit the form. In fact, the only reason something like that is included is so that your PHP code will only be executed after the form is submitted. – Don't Panic Aug 26 '16 at 21:41