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($studen tID, $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>
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($studen
}?>
<form method="post" id="customForm" action="<?php echo htmlentities($_SERVER['PHP
<div>
<label for="studentID">Student ID:</label>
<input id="studentID" name="studentID" type="text">
</div>
<div>
<label for="Password">Password:</
<input id="Password" name="Password" type="Password">
</div>
<div>
<input id="send" name="Login" type="submit" value="Login">
</div>
</form>
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?
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'].
ASKER
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.
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
Thank you.
ASKER
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?
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?
ASKER
canot use isset is not working
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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">
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">
Open in new window