Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/12899-a-variable-within-_post-possible/
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
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!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.