By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

Problem with $_POST variable

P: n/a
Hi,

I'm learning PHP and prepared a simple login form. validate.php does
the validation and it was behaving erratically. So, I did var_dump of
$_POST variable and it's NULL. Did I miss anything here regarding the
configuration or code? Code for validate.php is given below.

<?php
var_dump($_POST);

$user=$_POST['login'];
$password=$_POST['password'];

// .... Rest of the validation ...
?>
Any kind of help would be highly beneficial.

Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable ar**************@gmail.com's handwriting:
I'm learning PHP and prepared a simple login form. validate.php does
the validation and it was behaving erratically. So, I did var_dump of
$_POST variable and it's NULL. Did I miss anything here regarding the
configuration or code? Code for validate.php is given below.

<?php
var_dump($_POST);
Well, if you DUMP the $_POST var here...
$user=$_POST['login'];
$password=$_POST['password'];


.... then obviously you won't get anything here. $_POST is dumped, so
there is no such thing as $_POST[whatever]. Don't dump. :)

Besides, you should check whether there is anything in those vars:
if ( (isset($_POST['login'])) && (isset($_POST['password'])) ) then
{
// Validation here
}
else
{
// Error message ("No username/password supplied" for example) here
}

Cheers
Mike
Jul 17 '05 #2

P: n/a
My original code is
<?php
$user=$_POST['login'];
$password=$_POST['password'];

// .... Rest of the validation ...
?>

login and password fields were not empty when the form was submitted.
But still, $_POST['login'] and $_POST['password'] were not set (I've
confirmed it using isset() functions).

Can someone help?

Jul 17 '05 #3

P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable ar**************@gmail.com's handwriting:
My original code is
<?php
$user=$_POST['login'];
$password=$_POST['password'];

// .... Rest of the validation ...
?>

login and password fields were not empty when the form was submitted.
But still, $_POST['login'] and $_POST['password'] were not set (I've
confirmed it using isset() functions).

Can someone help?


Could you also include:
1. the form's HTML code
2. The filenames of both files (the form's file and the validating file
Jul 17 '05 #4

P: n/a
arun.kumar.va...@gmail.com wrote:
login and password fields were not empty when the form was submitted.
But still, $_POST['login'] and $_POST['password'] were not set (I've
confirmed it using isset() functions).


Sure your login and password fields in the form are named correctly? =\

Jul 17 '05 #5

P: n/a
I'm really sorry guys. PHP version on my server is 4.0.6. Found it out
with phpinfo()

Came to know that $HTTP_POST_VARS is the variable to use for the
versions earlier than 4.1.0

Jul 17 '05 #6

P: n/a

Michal Wozniak wrote:
<?php
var_dump($_POST);


Well, if you DUMP the $_POST var here...
$user=$_POST['login'];
$password=$_POST['password'];


... then obviously you won't get anything here. $_POST is dumped, so
there is no such thing as $_POST[whatever]. Don't dump. :)

This is absolutely false.

The "dump" in var_dump should be thought of as "dumping output to
screen". It is analagous to print or echo. It does not unset the
variable, or change it in any way.

It is very useful to use var_dump in the way the original poster used
it, because "print" would not work ( $_POST is an array ) and "print_r"
would produce incomplete results ( because $_POST might contain nested
arrays ). var_dump will echo all the contents of $_POST which is
useful for testing purposes.

Jul 17 '05 #7

P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Ramius's handwriting:
se var_dump in the way the original poster used
it, because "print" would not work ( $_POST is an array ) and "print_r"
would produce incomplete results ( because $_POST might contain nested
arrays ).**var_dump*will*echo*all*the*contents*of*$_POST* which*is
useful for testing purposes.


Oooops... Sorry, my mistake. :/
I stand corrected.

Regards
Mike
Jul 17 '05 #8

P: n/a
My "workaround" for this problem is something like:

put this code in any function that needs $_POST, $_GET, etc...
if ( !isset($_SERVER) )
{
global $HTTP_POST_VARS;
$_POST = &$HTTP_POST_VARS;
// do this for any other superglobal $_whatevers you need
}

Jul 17 '05 #9

P: n/a
ar**************@gmail.com wrote:
Hi,

I'm learning PHP and prepared a simple login form. validate.php does
the validation and it was behaving erratically. So, I did var_dump of
$_POST variable and it's NULL. Did I miss anything here regarding the
configuration or code? Code for validate.php is given below.

<?php
var_dump($_POST);

$user=$_POST['login'];
$password=$_POST['password'];

// .... Rest of the validation ...
?>
Any kind of help would be highly beneficial.

Odds are your problem is with your html. Double-check your variable
names in the html form as well as in your php source. Also, check your
form tag in your html. You may inadvertantly be using GET instead of
POST, in which case $_POST will contain nothing. Also, update to the
latest stable release of PHP. See below for an example.

test.html:
<form action="login.php" method="POST">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Submit">
</form>

login.php:
<?php
$user = isset($_POST['user']) ? $_POST['user'] : '';
$pass = isset($_POST['password']) ? $_POST['password'] : '';

echo 'Username: '.$user.'<br>Password: '.$pass;
?>
Jul 17 '05 #10

P: n/a
Ramius wrote:
"print_r"
would produce incomplete results ( because $_POST might contain nested
arrays ). var_dump will echo all the contents of $_POST which is
useful for testing purposes.


print_r() prints nested arrays.

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.