i was doing php forms , and the else statement is only being ouputed -


here code - dont problem is...

my form:

  <form action="process1.php" method="post" >        first name : <input type="text" name="first name" value="" />     password : <input type="password" name="pasword" value= "" />     <br/>     <input type="submit" name="submit" value="submit" />     </form> 

process1.php

    <?php     $users = array("abhishek","alan" ); # doing limit users       if (firstname == $users ){         $firstname = $_post['firstname'];         $password  = $_post[ 'password'];         echo "$firstname" . "and". "$password";      }else {          echo "access denied";     }       ?> 

even if type abhishek or alan output showing access denied:

notice: use of undefined constant firstname -   assumed 'firstname' in f:\wamp\www\php_sandbox\process1.php on line 9      access denied 

i know shouldn't answering due such low quality - it's perhaps helpful explain others (again , again , again)

the error notice: use of undefined constant firstname - assumed 'firstname' not clearer, firstname not variable. mean $firstname, mean define post data before using it.

see line-by-line commentary:

$users = array("abhishek", "alan"); // creates array if (firstname /* "firstname" */ == $users) { // you're comparing string array     $firstname = $_post['firstname']; // you're defining variable after you've used it, assuming corrected above     $password  = $_post[ 'password'];     echo "$firstname" . "and". "$password"; // here you're concatenating 3 strings needlessly }else {      echo "access denied"; }  

more valid code this, explained lbl:

$users = array("abhishek", "alan"); // define array $firstname = $_post['firstname']; // create $firstname posted data $password  = $_post[ 'password']; // create $password posted data if (!empty($firstname) && in_array($firstname, $users)) { // check if $firstname has value, , in array     echo "$firstname , $password";  // variables automatically placed in double quoted strings } else {     echo "access denied"; } 

you need correct html input fields have correct names:

first name : <input type="text" name="firstname" value="" /> password : <input type="password" name="password" value= "" /> 

i suggest reading lot more php / programming in general before continuing this, you'll have insecure system if build upon this.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -