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

Get all $_POST variables 1

Status
Not open for further replies.

BiggerBrother

Technical User
Sep 9, 2003
702
GB
I ahve a form, with over 50 checkboxes. When the form submits, I need to be able to iterate through all the $_POST varaibles, to create an sql string. I have no idea what these variables will be called, as they are related to the name of theproduct I am searching for.

Is there a way to return all the post variables, without knowing the name of each?

Many thanks,

BB
 
Here is some code that I use for something similar:
Code:
foreach($_POST as $variable => $value)
	echo "\n".'<input type="hidden" name="'.$variable.'" value="'.$value.'"/>';
Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
do you need to create a string for each checkbox since a checkbox can have multiple values ?? or just 1 total string?
 
A checkbox can have one value. You either select the checkbox (and the checkbox name and value are passed into the form collection upon submit) or you de-select it (in which case the name and value for the checkbox are never sent).

More details on HTML can be found in the HTML, XHTML and CSS forum at: forum215.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
that's called a radiobutton if it's yes or no.
checkbox is for multiple answers possible ;)

I have a nice script for checkboxes multiple values ;)
 
How are the checkboxes named? If you show us that code, we might be able to come up with a more effecient way of naming them so that your coding to check them is simple.

Ken
 
If your products are defined in a prefixed order - as in an array - you could send value as an index to that array, and colect the indexes in a new array.
After the submit, run thru the second array reading the indexes to the first array.

I'm doing this and it is working fine.

 
Sorry, I've been away for a couple of days, and so really bad at answering.

BabyJeffy, thanks, that put me on the right track.

Thanks

BB
 
nice article, I was always curious about that sql injection :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top