Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
trouble parsing $_POST data
Old 09-06-2007, 11:53 AM trouble parsing $_POST data
purk's Avatar
Extreme Talker

Posts: 164
Name: James
Location: marbella & surrey
Trades: 0
I'm trying to return the name attribute of a radio button from the $_POST data.

i'm never great at explaining my problem on paper so my -simplified- code below should make it clear, to smarter people than me, where i went wrong.

this is my html:
Code:
<input type="radio" name="rad_1" id="show_1 value="1">show
<input type="radio" name="rad_1" id="hide_1 value="0">hide
				
<input type="radio" name="rad_2" id="show_2 value="1">show
<input type="radio" name="rad_2" id="hide_2 value="0">hide

....etc.... this goes on an unknown number of times...
and this is my php:
Code:
foreach($_POST as $post_up) {
    if ($post_up['value']) $sql .= "INSERT INTO table VALUES ('" . $post_up['name'] . "')";
}

if i print_r($_POST) i get the expected Array ([rad_1] => 0, [rad_2] =>1 .....)
it's the bit inside the [square brackets] i need to return to use in my insert
statement.

if anyone has ANY input on this i'd be very grateful as i've spent hours googling and reading the php.net docs with little luck.

many thanks

purk



the reason for the iteration is at runtime i don't know exactly how many radio buttons there will be so i want to cycle through the whole of the $_POST.

my actual code is much bulkier so i stripped the unimportant stuff so if there are any glaringly obvious mistakes it's likely to be just in this posting as my code executes without errors (just not as i would like).
__________________

Please login or register to view this content. Registration is FREE
- private villas direct from the owners - travel links always needed.
purk is offline
Reply With Quote
View Public Profile Visit purk's homepage!
 
 
Register now for full access!
Old 09-06-2007, 01:37 PM Re: trouble parsing $_POST data
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Simply read the manual about foreach, and you'll see there are 2 syntax.
1 simplified with only the value, and a second with value and key.

I don't know how you could miss it, or maybe you searched everything appart foreach ?
Another way is to get a array containing only the keys (with array_keys), and then to use those keys to iterate the $_POST array, but foreach was made to avoid that situation.


http://www.php.net/manual/en/control...es.foreach.php
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 09-06-2007 at 01:39 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-06-2007, 02:06 PM Re: trouble parsing $_POST data
purk's Avatar
Extreme Talker

Posts: 164
Name: James
Location: marbella & surrey
Trades: 0
doh... i thought that the foreach was the only part of the code that was totally sound.

i will check out the php.net docs again.

thanks tripy
__________________

Please login or register to view this content. Registration is FREE
- private villas direct from the owners - travel links always needed.
purk is offline
Reply With Quote
View Public Profile Visit purk's homepage!
 
Reply     « Reply to trouble parsing $_POST data
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20429 seconds with 12 queries