Jump to content

'if'fing checkbox values.


Thauwa

Recommended Posts

Status - I have an HTML form, which has checkboxes named c1, c2, c3 & c4.

            When checked, the value (thing I want to insert to mysql) must be 'yes', and the remaining must be valued 'no'.  ???

 

Situation- I can't find how to do it.  :-\

 

Help! Does anyone know how to achieve this? Thanks in advance!

Link to comment
Share on other sites

When a checkbox is unchecked, nothing is sent via POST. When a checkbox is checked, it's html value feild is sent. For setting a variable to yes or no if the checkbox is checked or unchecked, you can check it using the isset function.

 

$c1 = (isset($_POST['c1'] ? "yes" : "no");
$c2 = (isset($_POST['c2'] ? "yes" : "no");
$c3 = (isset($_POST['c3'] ? "yes" : "no");
$c4 = (isset($_POST['c4'] ? "yes" : "no");

Link to comment
Share on other sites

I think that the new code is correct, because, when the previous code is put,

Parse error: syntax error, unexpected '?', expecting ',' or ')' in D:\Hosting\3577251\html\quiz\submit.php on line 6

 

occurs.

Thanks, I'll try the new one!

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.