Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 26 June 2006 - 03:26 AM

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

#2 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 28 June 2006 - 03:43 AM

any idea guys? this is driving me nuts

#3 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 28 June 2006 - 07:37 AM

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--]dynaminity[!--colorc--][/span][!--/colorc--]....to create the validation?
I hope that made sense
I'm really tired

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#4 wdo_will

wdo_will
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 July 2006 - 08:56 PM

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.

<?php 
//start loop

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

//add checkbox to database

}

//end loop
?

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


<?php 
//start loop

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

//add checkbox to database

}

//end loop
?

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


<?php 
//start loop

$var = "checkboxName_$variable";

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

//add checkbox to database

}

//end loop
?

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users