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
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
}

Link to comment
Share on other sites

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.