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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems passing array and index using $_POST

Status
Not open for further replies.

hvass

Programmer
Mar 16, 2002
192
GB
I have a page generated by a php script that creates n tables each with their own submit button

echo "form type='POST' target='secondphppage.php'";

for $i=0 to n
echo &quot;<input type='submit' value='button$i'>&quot;;
echo &quot;<input type='hidden' name='queryarray[]' value='$myquery'>&quot;;

The target php script does
$queryarray=$_POST[queryarray];

I can then pick up the array of queries with ease $query=$queryarray[3] but how best to pass the information on which submit button was pressed? i want to be able to say $query=$queryarray[$buttonnumber];

(appologies the example above is in franglais code I cannot remember php syntax without it in front of me)

I just need a pointer on how to do it - do I generate multiple forms ? can I pass something on the url as in target='secondphppage.php?buttonnumber=3' and do a get as well as a post ?
am I just missing the plot is there an obvious way to do this ?

Thanks in advance
 
just add another INPUT type=hidden value=$count...
does it make sense for you?
 
Or you could just name your submit buttons.

With the following HTML:

Code:
<html><body>
<form method=&quot;post&quot; action=&quot;test_submit.php&quot;>
<table>
	<tr><td><input name=&quot;foo&quot;></td><td><input type=submit name=&quot;submit2&quot; value=&quot;submit1&quot;></td>
	<tr><td><input name=&quot;bar&quot;></td><td><input type=submit name=&quot;submit1&quot; value=&quot;submit2&quot;></td>
</table>
</form>
<html><body>

If I click on the button named &quot;submit1&quot;, $_POST will contain something like the following:

Code:
Array
(
    [foo] => a
    [submit2] => submit1
    [bar] => 
)


You can in such cases test for which of the button names appears in $_POST.



Want the best answers? Ask the best questions: TANSTAAFL!!
 
hvass, sleipnir's post is better than mine... Sleipnir is the one!!
 
Thanks sleipnir214
Obvious I suppose an input type of submit has a name & value as well so ends up getting passed in $_POST presumably only the selected submit gets passed - I will try it next week, thanks at least it won't be bugging me all week end.

Thanks Chacalinic
I had trouble trying to pass another hidden field as until the user presses the button I don't know what value to pass.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top