web page - Check Box - How to update Mysql Data

I created a form using PHP.  I have it linked to mysql and when someone select the Button the form they to send the data to MySQL, the check box data is not getting written to the database.
  Well the Name, address, email, all work fine they will update MySQL data base....but I not sure how to write code to update MYSQL from the check box?


********************Update MYSQL*********************************
('$_POST[RegDate]','$_POST[FirstName]','$_POST[LastName]','$_POST[EmailAddress]','$_POST[PhoneNumber]','$_POST[CECredits]')";
//THIS IS A TEST
  /*if (empty ($_Post["RegDate"]))*/
    /*{$$RegDate = $_POST['RegDate'];*/
  $RegDate = $_POST['RegDate'];
  //$IP = $_POST['IP'];
  $FirstName = $_POST['FirstName'];
  $LastName = $_POST['LastName'];
  $EmailAddress = $_POST['EmailAddress'];
  $PhoneNumber = $_POST['PhoneNumber'];
  $CECredits = $_post['CECredits'];

Open in new window

*****************form (Create Entry form_)********************************
<form action="http://www.biotone.com/insert.php" method="post" class="ohregister" style="padding:10px 0 0 15px; color:#b61351;">
        <fieldset style="width:400px; border:1px solid #b61351;">
          <legend style="font-size:16px; color:#b61351;"><b>SIGN UP NOW</b> </legend>
          <p>
            <label style="text-align:right; width:150px; float:left;">First Name: </label>
            <input type="text" name="FirstName" style="width:200px;" />
          </p>
          <p>
            <label style="text-align:right; width:150px; float:left;">Last Name: </label>
            <input type="text" name="LastName" style="width:200px;" />
          </p>
          <p>
            <label style="text-align:right; width:150px; float:left;">Email: </label>
            <input type="text" name="EmailAddress" style="width:200px;" />
          </p>
          <p>
            <label style="text-align:right; width:150px; float:left;">Phone: </label>
            <input type="text" name="PhoneNumber" style="width:200px;" />
          </p>
          <p>
            <label style="text-align:right; width:190px; float:left;">CE Credits? (Yes)  *:</label>
            <input type="Checkbox" name="CECredits" style="width:180px;" id="CECredits" />

Open in new window

Scott JohnstonSystems ConsultantAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
The default value for a checkbox is 'on' which is 2 characters, not 1, so the value won't fit in the field so it won't be inserted.  You could use value="Y" to make it one character.
<input type="Checkbox" name="CECredits" style="width:180px;" id="CECredits" value="Y" />

Open in new window

0
 
Kim WalkerWeb Programmer/TechnicianCommented:
You should give your checkbox a value to pass to the database.
<input type="checkbox" name="CECredits" style="width:180px;" id="CECredits" value="some value" />

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
If the checkbox is not checked, it will Not be posted.  That's the way checkboxes work.  This is the way I handle all the $_POST data.  This way, even when it is not checked, it has a default value and you won't get the 'missing index' error.
if (!isset($_POST['CECredits'])){$CECredits = "";} else {$CECredits = $_POST['CECredits'];}

Open in new window

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Ray PaseurCommented:
If you're new to PHP and want some good learning resources, this article will help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Checkboxes are unique in HTML forms input, in that if they are not checked, they do not appear in the request variables.  This article explains how it works with some examples.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html

If you read that over and still have questions, please post back and I'll show you some examples (however most examples that are good for teaching the principles will simply duplicate the examples in the article).
0
 
Ray PaseurCommented:
Kind of a sidebar note, but you might want to fix this before you release the web site into the wild.  Google does not like to index sites with invalid markup!
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.biotone.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
My friends, thank you for your all your comments but it is not  resolving the problem.  The value always comes up "null" in my sql.
 I must have the field incorrectly setup.

Varchar, 1 length,  Default is Null, NULL is YES
0
 
Ray PaseurCommented:
Try defining the SQL column this way:

CECredits VARCHAR(1) NOT NULL DEFAULT ''

Open in new window

Then you can test for an empty() string from the data base to indicate "not checked" and any condition other than empty() indicates "checked."  You can find rows with checked values in a query like this:

SELECT things FROM tables WHERE CECredits <> ''

Open in new window

You can find rows with unchecked values with a query like this:

SELECT things FROM tables WHERE CECredits = ''

Open in new window

If you want to set up your HTML documents to provide a default value for the CDCredits input, read the article about checkboxes for understanding, paying particular attention to the paragraph with "How do I get a default value for a checkbox?"  It teaches how to use type=hidden form controls to make your life easier.
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
Sorry, I still working on this project and have not been able to confirm or deny results...I should be able review all comments tomorrow.
Scott
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
Tis fixed my situation. I needed to setup the field with 2 characters.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.