473,779 Members | 2,023 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 14696
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
4632
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 content of this page is presented in one form. The problem:
3
2677
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. function doAction(actn) { document.forms.dbaction.value = actn;
3
4373
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
2312
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 redirect to a different page. When I "echo" from within the code (for testing), it displays showing the...
1
2435
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
1191
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
1579
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. lets say i submitted the form and went to test.py and the output was correct, then, while i'm on...
0
961
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
3517
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
9632
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9925
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
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.