Solved

web page - Check Box - How to update Mysql Data

Posted on 2014-04-21
10
780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 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 83

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 110

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 110

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 83

Accepted Solution

by:
Dave Baldwin earned 500 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 110

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

695 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