Jump to content

php variable value issue


shah

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/157989-php-variable-value-issue/
Share on other sites

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
}

Archived

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

×
×
  • 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.