473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Problem with $_POST variable

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
10 14666
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
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
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
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
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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan Wood | last post by:
I am developing a regisration page that will present a set of check boxes to the viewer. This list of checkboxes is developed from a list in a database so the amount and names of the boxes will...
3
by: Thomas Hoheneder | last post by:
Hello, I use PHP 4.3.10 and want to deliver a post variable from a PHP page to itself. In my page mypage.php I have a hidden field named "dbaction" and a form button. When clicking the form...
3
by: J˙Gius³ vs ::NRG::ius | last post by:
Hi all. I have a script with a form <form action="a.php" ... method="post"> <input name="field" ...> </form> a.php gets the variable with
4
by: Lee David | last post by:
I have a validation form that lets you enter your ID and password. Then I call the page again. This time the page script should check that it is a "recall" and check the entered data with the...
1
by: unknown; | last post by:
hello i'm using a php script opening en parsing a url like www.OpenThisURL.com/site.php?a=aa&b=bb this url and website are not mine but i'm only using some information from the site. now...
4
by: jamietsh | last post by:
Because i've already used perl to write my program, i now need to have a button to extract the variable and post them to a notepad to make it like a report. Is there any way to do this? Thanks.
5
by: pavloutefkros | last post by:
sorry for creating a new post but this is totally different from the previous one. Here is the problem (which is very hard to explain, so i will use a paradigm): i submit a form and the post...
0
by: Terry Reedy | last post by:
dudeja.rajat@gmail.com wrote: As Tim noted, this cannot run. *** Always post the code you actually ran *** So we cannot answer why the code you did not post did not work. With the mod/mod1...
5
by: mfaisalwarraich | last post by:
hi everybody, please tell me how i can get red of escaping problem. im not very much familiar with PHP so i hope anybody can help me here I am trying to get the values in a form if back button...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.