Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie needs help with 'POST' variables

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
0
0
US
I am having a problem programming the code for a 'POST' form. I can't seem to get anything out of $_POST[]. Below is what I think are the relevant sections of code:
Code:
<?php
$dir=&quot;e:/ftp-root/uploads/sors/&quot;;
$alias=&quot;ftp-sors/&quot;;
$dh=opendir($dir);
$i=1;
if(!isset($_POST['Submit']))
{
?>
<form name=&quot;SORSAdministration&quot; action=&quot;sorsreview.php&quot; method=&quot;post&quot;>
	<table border=&quot;0&quot; summary=&quot;&quot;>
		<tr>
			<td width=&quot;275&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>File Name</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Accept</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Reject</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Defer</font></b></td>
			<td width=&quot;275&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>File Name</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Accept</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Reject</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Defer</font></b></td>
		</tr>
<?php
	while (false !== ($file=readdir($dh))) if (is_file($dir.$file))
	{
		if ($file !== &quot;.htaccess&quot;)
		{
			if ($i % 2 !== 0) echo &quot;<tr>\n&quot;;
			echo &quot;<td width=\&quot;275\&quot;><font size=\&quot;+1\&quot; color=\&quot;#008000\&quot;><a href=\&quot;[URL unfurl="true"]http://$SERVER_NAME/$alias$file\&quot;>$file</a></font></td>\n&quot;;[/URL]
			echo &quot;<td width=\&quot;58\&quot;><font size=\&quot;+1\&quot; color=\&quot;#008000\&quot;><input type=\&quot;radio\&quot; name=\&quot;Disposition$i\&quot; value=\&quot;Accept\&quot;></font></td>\n&quot;;
			echo &quot;<td width=\&quot;58\&quot;><font size=\&quot;+1\&quot; color=\&quot;#008000\&quot;><input type=\&quot;radio\&quot; name=\&quot;Disposition$i\&quot; value=\&quot;Reject\&quot;></font></td>\n&quot;;
			echo &quot;<td width=\&quot;58\&quot;><font size=\&quot;+1\&quot; color=\&quot;#008000\&quot;><input type=\&quot;radio\&quot; name=\&quot;Disposition$i\&quot; value=\&quot;Defer\&quot; CHECKED></font></td>\n&quot;;
			if ($i % 2 == 0) echo &quot;</tr>\n&quot;;
			$i++;
		}
	}
	if ($i % 2 !==0) echo &quot;</tr>&quot;; // last entry might need row ender
	closedir($dh);
?>
	</table><br>
	<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form><br>
<?php
	}
	else
	{
		while (false !== ($file=readdir($dh))) if (is_file($dir.$file))
		{
			if ($file !== &quot;.htaccess&quot;)
			{	
				$disp=$_POST['disposition1'];
				echo &quot;disposition=$disp<br>&quot;;
				$i++;
			}
		}
		closedir($dh);
	}
?>
Bascially I am creating a table with contains extracted file names and for each file there is a radio button for its disposition. Setting aside the attempt to set up the radio buttons names as an array, I cannot get anyting values out of the 'echo' near the bottom. The page displays fine and the source looks good. But when the submit button is pressed no values are retreived from $_POST. I need help understadning how to use $_POST to get my radio buttton values.

TIA.
 
Thanks for the reply. I assume you meant $_POST. All it printed was &quot;Array&quot;.
 
I don't get anything the first time (that is not where I put the 'echo'). The 2nd time is when I get 'Array' (not 'Array()').

I take it from your response you did not see anything obvious in my code.

P.S. I'm using PHP 4.1 (bundled with OpenSA).
 
I think I've proven there is something fundamentally wrong with my form. I printed out 'array_values($_POST)' and all I got was &quot;Array'. I think this means nothing was really posted. Can someone re-look at my code and see where I'm going wrong. Somehow the values of 'dispostion' for my radio butttons are not being posted.

Thanks.
 
guys i think the problem here is that, you get &quot;Array&quot; when try to
print_r[$_POST]
that means the data in their is an array, that's what i came up to few days ago and couldn't work out what to do, so i did this and worked perfectly... try it

i specified the varibles like this

put the name you like instead of $try

$try = $HTTP_POST_VARS['your_post_variable_name'];
//than put this statment as many variables you have in the last form than try

echo $try;

it worked for me, just give it a go..
thanks
 
Thanks. I thought that form was obsolete with PHP >=4. I'll give it a try later today and report back.
 
Sorry, that didn't help at all. Perhaps if I posted the resulting source on the first pass, someone might be able to spot something:
Code:
<html>
<!-- Generated by AceHTML Freeware [URL unfurl="true"]http://freeware.acehtml.com[/URL] -->
<!-- Creation date: 5/28/2003 -->
<head>
<title></title>
<meta name=&quot;SORS ADministration&quot; content=&quot;&quot;>
<meta name=&quot;xxxxxxxxxxx&quot; content=&quot;xxxxxxxxxxxxxxxxxx&quot;>
<meta name=&quot;generator&quot; content=&quot;AceHTML 5 Freeware&quot;>
</head>
<body>
<h1><font color=&quot;#0000ff&quot;><div align=&quot;center&quot;>SORS Live Broadcast Commercial Review</div></font></h1>
<form name=&quot;SORSAdministration&quot; action=&quot;sorsreview.php&quot; method=&quot;post&quot;>
	<table border=&quot;0&quot; summary=&quot;&quot;>
		<tr>
			<td width=&quot;275&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>File Name</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Accept</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Reject</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Defer</font></b></td>
			<td width=&quot;275&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>File Name</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Accept</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Reject</font></b></td>
			<td width=&quot;58&quot;><b><font size=&quot;+1&quot; color=&quot;#008000&quot;>Defer</font></b></td>
		</tr>
<tr>
<td width=&quot;275&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><a href=&quot;[URL unfurl="true"]http://66.245.6.139/ftp-sors/Intro[/URL] ad.wav&quot;>Intro ad.wav</a></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition1&quot; value=&quot;Accept&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition1&quot; value=&quot;Reject&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition1&quot; value=&quot;Defer&quot; CHECKED></font></td>
<td width=&quot;275&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><a href=&quot;[URL unfurl="true"]http://66.245.6.139/ftp-sors/off[/URL] air.wav&quot;>off air.wav</a></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition2&quot; value=&quot;Accept&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition2&quot; value=&quot;Reject&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition2&quot; value=&quot;Defer&quot; CHECKED></font></td>
</tr>
<tr>
<td width=&quot;275&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><a href=&quot;[URL unfurl="true"]http://66.245.6.139/ftp-sors/rich[/URL] close.wav&quot;>rich close.wav</a></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition3&quot; value=&quot;Accept&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition3&quot; value=&quot;Reject&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition3&quot; value=&quot;Defer&quot; CHECKED></font></td>
<td width=&quot;275&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><a href=&quot;[URL unfurl="true"]http://66.245.6.139/ftp-sors/stationID.wav&quot;>stationID.wav</a></font></td>[/URL]
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition4&quot; value=&quot;Accept&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition4&quot; value=&quot;Reject&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition4&quot; value=&quot;Defer&quot; CHECKED></font></td>
</tr>
<tr>
<td width=&quot;275&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><a href=&quot;[URL unfurl="true"]http://66.245.6.139/ftp-sors/test[/URL] pattern.wav&quot;>test pattern.wav</a></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition5&quot; value=&quot;Accept&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition5&quot; value=&quot;Reject&quot;></font></td>
<td width=&quot;58&quot;><font size=&quot;+1&quot; color=&quot;#008000&quot;><input type=&quot;radio&quot; name=&quot;Disposition5&quot; value=&quot;Defer&quot; CHECKED></font></td>
	</table><br>
	<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form><br>
</body>
</html>
Thanks for any help?
 
There's nothing wrong with the HTML, one </tr> tag's missing just before the </table> four lines from the bottom.

However, look at this:
Code:
if ($file !== &quot;.htaccess&quot;){    
   $disp=$_POST['disposition1'];
   echo &quot;disposition=$disp<br>&quot;;
   $i++;
}

1. You hardcoded just to look at 'disposition1'. That's not what you want.
2. PHP variables are case sensitive. So, there is no 'disposition1' because the <INPUT> tags is named 'Disposition1'.

You need to fix the case and then actually loop through the $_POST variables.
Take sleipnir214's advice and stick the print_r($_POST) in your else statement just before the while loop. They are all there.
 
Well, DUH!

I can't believe how dumb I was. That cured the problem. Thanks.
 
As a debugging note... you said print_r($_POST); just outputted Array, and not Array().

That almost certainlly means you were using print and not print_r. I point this out, because

Code:
echo &quot;<pre>&quot;;
print_r($_POST);
echo &quot;</pre>&quot;;

is invaluable in debugging, so you might want to make sure you get this right :)

G'Luck

-Rob
 
Send form with array value?

<input type=\&quot;radio\&quot; name=\&quot;Disposition[]\&quot; value=\&quot;Reject\&quot; />

Look at the array Disposition[]. Use this if you need different values with one name.

can retrive it using;
$var = $PHP_POST_VARS['Disposition'];
foreach($var as $key=>$value){
echo &quot;$key = $var <br />&quot;;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top