Link to home
Start Free TrialLog in
Avatar of tankergoblin
tankergoblin

asked on

why my $_SERVER['PHP_SELF'] is not working

How would i go about making a PHP self submitting form that would accept HTML for input into a text box and output the result of the same html page... much like www.practiceboard.com ?

This is my basic form

when i press submit nothing shows...

<?php
if(isset($_POST['login'])){

                  $studentID = $_POST['studentID'];
                  $password =  $_POST['Password'];
                echo $password;
                  
                  $newStudent = new student;
                  $newStudent->login($studentID, $password);
                  
                  }?>




<form method="post" id="customForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
                  <div>
                        <label for="studentID">Student ID:</label>
                        <input id="studentID" name="studentID" type="text">
                        
                  </div>
                  <div>
                        <label for="Password">Password:</label>
                        <input id="Password" name="Password" type="Password">
                        
                  </div>
                  
                  <div>
                        <input id="send" name="Login" type="submit" value="Login">
                  </div>
            </form>
Avatar of StingRaY
StingRaY
Flag of Thailand image

Omitting "action" attribute causes the form submit to itself.

<form method="post" id="customForm">

Open in new window

Avatar of tankergoblin
tankergoblin

ASKER

erm so is that mean do not use PHP_SELF?


i would like to use $_post['testing'] and show the variable in the same page... can i do that after i get rid of action?
Yes, unless you remove "method" attribute, you can access $_POST['studentID'].
why i received this error message?

Undefined index: studentID in \file\dir\...

but when i press submit it is working..

may i know in the sense of security is it safe

and why i saw some developer using this code?
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>

Thank you.
i know i can use this below to get rid of the message

if (!isset($_POST['password']))
                                          {
                                          $_POST['password'] = " ";
                                          $password =$_POST['password'];
                                          }else{
                                          $password = $_POST['password'];
                                          }
                  

but does it safe to do as above... and is it a good practise?
canot use isset  is not working
ASKER CERTIFIED SOLUTION
Avatar of StingRaY
StingRaY
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your mistake is in the following line
if(isset($_POST['login'])){

use capital L for login i.e use

if(isset($_POST['Login'])){

Your script should work then.
This is because you have used capital L in the following line
<input id="send" name="Login" type="submit" value="Login">