Jump to content

[SOLVED] Checkbox insert & retrieve from Database


aeafisme23

Recommended Posts

So i have created a form that easily adds/edits/deletes to a database except for the fact i cant update any of my checkboxes to the databases, only my input fields get updated. I just want the selected input to just update in the database under its field name/value to either be yes or no is sufficient enough. I'll give you my code and then a few of what i was thinking might be the problem, really interested in understanding this :)

    // this input addresses updates to database but the typeii checkbox does not updated and leaves the db blank

<tr valign="baseline">
      <td align="right" nowrap><div align="left">Address:</div></td>
      <td><input type="text" name="address" value="<?php echo $address ?>" size="32"></td>
      <td> </td>
      <td align="right" nowrap><div align="left">City:</div></td>
      <td><input type="text" name="city" value="<?php echo $city ?>" size="32"></td>
    </tr>
<td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input <?php if (!(strcmp("yes","no"))) {echo "checked=\"checked\"";} ?> type="checkbox" name="typeii" value="<?php echo $typeii ?>" id="checkbox2">
      Type II (Conventional Anodize)</div></td>

 

Should i be more concerned with how each checkbox has its own id of checkbox(1,2,4,5,etc...) ex) id="checkbox2" ? and do a php echo of the vlue of checkbox2 and not my own determined name for it as typeii?

<input type="checkbox" name="typeii" value="<?php echo $typeii ?>" id="checkbox2">

 

Link to comment
Share on other sites

if ($typeii != NULL) {

$typeii = "YES";

}

else {

$typeii = "NO";

}?>

 

and then i made input box <input type="checkbox" name="typeii" value="<?php echo $typeii ?>"> and it works, i guess i just needed to go at it harder. Thought i would at least give the community a solved so someone can benefit besides me.

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.