PDA

View Full Version : $_POST data not getting through


phrygius
02-25-2005, 03:16 PM
I'm trying to do a simple web form to email application. Something I've had no trouble with for a few times doing the same thing. The only difference is that I didn't write the form. It was automatically created by some free form handling site. The owner wants it to be local now, so I'm trying to re-write it.

When I try to access the $_POST data, its all empty. The only thing I can think of is that in addition to the "name" attribute in the <input>'s, this form has an "id" tag too. But that wouldn't screw with anything, would it? I'm trying to access by $_POST[name], not $_POST[id]

Any ideas?

Mr. Popularity
02-25-2005, 03:20 PM
it should be like this:

$variable = $_POST['inputname'];

notice the ' surrounding the form input name :)

Silmaril8n
02-25-2005, 03:31 PM
Make sure that you aren't trying to display or manipulate the data through a function without passing the variable in. Only the initial page being loaded will be in the scope of $_POST. Any functions called in that page would have to use a variable contained in $_POST as an argument. I've done this sooo many times to myself!

Viper007Bond
02-25-2005, 08:09 PM
If adding ' didn't fix it, post your whole source code here or upload it somewhere and rename it to a .phps file and link to it.

phrygius
02-25-2005, 09:15 PM
If adding ' didn't fix it, post your whole source code here or upload it somewhere and rename it to a .phps file and link to it.

Here's one part of the form. I took the "id" attribute out of the first input, but from the 2nd one on, there is an "id".


<FORM action="./dailyreporthandle.php" method="POST">
<H3>
<CENTER>
<table border="1" align="center" cellpadding="2" cellspacing="0" halign=center>
<tr>
<td width="61%"><b>Project Name:</b></td>
<td width="39%"><input name="ProjectName" type="text">
</td>
</tr>
<tr>
<td width="61%"><b>Project Number:</b></td>
<td width="39%"><input name="Project Number" type="text" id="ProjectNumber">
</td>



Then here is some of the php that handles it:


<?php
echo $_POST["ProjectName"];
echo $_REQUEST["ProjectName"];
echo "<br>";


if(empty($_POST["ProjectName"]))
{
echo "Not Validated";
}

else
{
echo "Validated";
}


The two top echo statements dont print anything out when I submit with that field populated, and the if statement always gets hit, never the else. I'd like to make that validation if statement a long compound one eventually. Also, I've tried a few different evaluations for the if statement, like isset(), and == "", etc.

Thanks for any help you can give.

Viper007Bond
02-25-2005, 09:22 PM
Try this:

nl2br(print_r($_POST));

nl2br will convert line breakes to <br />'s and print_r will print out the whole variable in a human readable format.

Silmaril8n
02-25-2005, 09:35 PM
That's what I was going to suggest. Dump your POST array and see what you're actually dealing with. A great method for basic debuggin.

iDxMan
02-28-2005, 12:09 AM
<input name="Project Number" type="text" id="ProjectNumber">

Your HTML is faulty. Note the name="Project Number".

...so in php, you would need:


echo $_POST['Project Number'];


As Viper007Bond posted, I'd dump the entire $_POST array just to see what's coming through or not..

I typically do something like:
echo '<pre>'; print_r($_POST); echo '</pre>';

(I'd also change the var name, but whatever works)

-r

phrygius
02-28-2005, 03:01 PM
I got it working thanks to that print_r function. That was a huge help, thank you all.

Apparently there were some underscores replacing the spaces, so I was trying to access variables with spaces that didnt exist.

Thanks again!

Viper007Bond
02-28-2005, 04:45 PM
Ah. Yeah, it's not a good idea to use spaces in form names, input names, etc. I also always use lowercase, but maybe that's just me.

iDxMan
02-28-2005, 11:14 PM
Ah. Yeah, it's not a good idea to use spaces in form names, input names, etc. I also always use lowercase, but maybe that's just me.

Same here. I try to stick to lowercase and use underscores if necessary. I'd rather have 'var_foo_something' instead of 'ThisSpecialWhippyVar' where the cap was causing problems..

-r

Viper007Bond
02-28-2005, 11:29 PM
You just gotta name it something. Hell, you could name it "input" assuming you won't get conflicts. :p