Jump to content

Archived

This topic is now archived and is closed to further replies.

john_6767

a variable within $_POST['']? possible?

Recommended Posts

ok, i'm trying to get multiple checkboxes going and i think i have everything sorted except i cannot check to see if the checkbox is checked, the checkboxes are dynamic so i cannot type in the name as it changes so what i was trying to do is

//start loop

if (isset($_POST['checkboxName_$variable'])) {

//add checkbox to database

}

//end loop

where $variable is a number i put after every checkbox to make them unique. So why isn't it working (is it due to having a variable in the post['']) and how could i do the checkbox check differently?

Also my logic for this system above is that a checkbox only comes trhough if it is checked, and i add it to the db if checkbox is checked but not if not checked. Anyone see any potential problems,

cheers

Share this post


Link to post
Share on other sites
how are you naming them again........?
is the name so dynamic that you can't create the same ....[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][i]dynaminity[/i][!--colorc--][/span][!--/colorc--]....to create the validation?
I hope that made sense
I'm really tired

Share this post


Link to post
Share on other sites
It is possible with any other array, so I'm sure it will work here.

The problem is that variables are only read within double quotes ("$var").  So, if you make $var = 'hi', and say echo '$var'; it will not work.  But if you say echo "$var"; or echo $var; it will work.

So, basicly, there are three ways to do this.

[code]<?php
//start loop

if (isset($_POST['checkboxName_'.$variable])) {

//add checkbox to database

}

//end loop
?[/code]

This will make the variable out of the $_POST array have two strings, ie 'checkboxName_' and then $variable (hope that makes sense  :-\)


[code]<?php
//start loop

if (isset($_POST["checkboxName_$variable"])) {

//add checkbox to database

}

//end loop
?[/code]

This does the same as your example, but actually reads the variable.


[code]<?php
//start loop

$var = "checkboxName_$variable";

if (isset($_POST[$var])) {

//add checkbox to database

}

//end loop
?[/code]

This puts the entire sting that you want to grab out of the $_POST array into a variable.

I hope you can understand this post, I can't think of how to explain everything properly!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.