?
Solved

web page - Check Box - How to update Mysql Data

Posted on 2014-04-21
10
Medium Priority
?
810 Views
Last Modified: 2014-05-12
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

0
Comment
Question by:Scott Johnston
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:Kim Walker
ID: 40013535
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40013538
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40013546
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40013555
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
 

Author Comment

by:Scott Johnston
ID: 40013592
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1500 total points
ID: 40013760
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40014559
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
 

Author Comment

by:Scott Johnston
ID: 40028508
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
 

Author Closing Comment

by:Scott Johnston
ID: 40059845
Tis fixed my situation. I needed to setup the field with 2 characters.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question