Jump to content

Recommended Posts

well i got a few checbox (look below for code)

i want to make it so that if i click the checkbox's it sends all the check box value to one column with "," in between them

      
<input type="checkbox" name="genre" value="fighting" id="genre"/>fighting
<input type="checkbox" name="genre" value="school life" id="genre" />school life
<input name="genre" type="checkbox" id="genre" value="king" id="genre" />king 
<input name="genre" type="checkbox" id="genre" value="him" />him

Link to comment
https://forums.phpfreaks.com/topic/224913-checkbox-database-error/
Share on other sites

You need to provide your php, as this is what will put the information into the database.

 

You will also need to set the values of the checkboxes into an array. Something that I found out this week myself.

 

When you process the form, you can check through the checkboxes array to see if it's set or not, and then append the value to a checkboxes string, which is then put into the datase.

 

Denno

So basically, you want the values from all the boxes that are checked? If so, the first problem is that you'll need to change the checkbox code.

 

Your current code has four checkboxes with the same name. So when the data is sent back to the server you'll only have one value if more than one is checked.

 

<input type="checkbox" name="genre" id="genre" value="fighting" />fighting
<input type="checkbox" name="genre" id="genre" value="school life" />school life
<input type="checkbox" name="genre" id="genre" value="king" />king
<input type="checkbox" name="genre" id="genre" value="him" />him

 

 

Instead you'll want the checkboxes to have different names and ids.

 

<input type="checkbox" name="genre1" id="genre1" value="fighting" />fighting
<input type="checkbox" name="genre2" id="genre2" value="school life" />school life
<input type="checkbox" name="genre3" id="genre3" value="king" />king
<input type="checkbox" name="genre4" id="genre4" value="him" />him

 

 

Now you'll have four different variables to work with in your script:

 

echo $_GET['genre1'] . ', ';
echo $_GET['genre2'] . ', ';
echo $_GET['genre3'] . ', ';
echo $_GET['genre4'] . ', ';

 

 

Note that if your form is set to method="post" you'll need to change the above variables to $_POST['genre1'], etc.

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.