473,586 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=$_POS T['password'];

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

Jul 17 '05 #1
10 14681
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=$_POS T['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=$_POS T['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=$_POS T['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=$_POS T['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*wi ll*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_VAR S;
// 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=$_POS T['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.p hp" 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>Pa ssword: '.$pass;
?>
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4620
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 change. This portion works just fine. The page content has a user name and password along with several sets of these checkboxes. All the form...
3
2669
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 button a javascript function is called where the dbaction hidden field is set to the value "change" (=actn) and then the form gets submitted....
3
4369
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
2306
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 database. With a match, set three cookies (this doesn't work) and redirect to another page. With a miss, see the cookies to "guest" values and...
1
2427
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 this site has changed and the GET variable a=aa & b=bb have
4
1185
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
1572
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 variable is being sent to the page test.py. then the test.py retrieves the POST and print it to the page. now everything is great except one thing. ...
0
952
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 mixup fixed, you do not need the update function. mod.a = 20 should do the same thing.
5
3511
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 of browser is used. here is the code that im using: echo('
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.