shah Posted May 13, 2009 Share Posted May 13, 2009 Hi all, i have a problem with php variable names. i am having a check box (actually a lot of check boxes, dynamically being generated from database strings), whos name is like [NT]cartoon. for example i am having the following code in php echo "<td><input type=\"checkbox\" name=\"$name\" value=\"$_post[$name]\"> $name</td>"; where the name is [NT]cartoon. now my issue is that when this variable is used inside $_POST, it does not work because it will be like $_POST["[NT]cartoon"] because of these brackets in the variable value. Kindly tell me how can i make it work Thanks Quote Link to comment https://forums.phpfreaks.com/topic/157989-php-variable-value-issue/ Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 It should be $_POST[$name]. Quote Link to comment https://forums.phpfreaks.com/topic/157989-php-variable-value-issue/#findComment-833341 Share on other sites More sharing options...
wildteen88 Posted May 13, 2009 Share Posted May 13, 2009 Yes your problem is to do with the square brackets. What is '[NT]cartoon' ? Is that someone username from your site? I wouldn't recommend naming your checkboxes with peoples usernames. You should name your checkboxes as users[] then just pass their username as its value. When you process your checkboxes do foreach($_POST['users'] as $user) { echo $user .' was selected<br />'; // do what ever here } Quote Link to comment https://forums.phpfreaks.com/topic/157989-php-variable-value-issue/#findComment-833368 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 wildteen88, you have a syntax error in your echo statement. Edit - nevermind. Quote Link to comment https://forums.phpfreaks.com/topic/157989-php-variable-value-issue/#findComment-833369 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.