I have a form with several checkboxes that I would like to save a bit value in the corresponding column in mySQL. As far as the html is concerned, I have each checkboxs' value set to '1'. I have created variables to capture the POST value for each html field, and then I use that variable in a SQL insert statement.
On the database side, the columns where the checkboxes will be saved are currently varchar(32) with a default value of '0'. I plan to change them back to a bit value once I have things working correctly. Currently, I receive a SQL error if any of the checkboxes are unchecked. If all of the checkboxes are checked, the value in the checkbox columns does not equal '1' as I would have expected.
Code:
if(isset($_POST['action']) && $_POST['action'] == 'submitform') { $personalizedname = $_POST['personalizedname']; $personalizedaddress = $_POST['personalizedaddress']; $personalizedphone= $_POST['personalizedphone']; $mountain = $_POST['mountain']; $surfboards = $_POST['surfboards']; $bird = $_POST['bird']; $sailboats = $_POST['sailboats']; $beach = $_POST['beach']; $name = $_POST['Name']; $company = $_POST['Company']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $citystatezip = $_POST['citystatezip']; $phone = $_POST['phone']; $email = $_POST['email']; $comments = $_POST['comments']; //$type = $_POST['type']; $mailingbrochureoffer = $_POST['mailingbrochureoffer']; $emailoffer = $_POST['emailoffer']; $tradeshowoffer = $_POST['tradeshowoffer']; $otheroffer = $_POST['otheroffer']; $othertext = $_POST['othertext']; $couponcode = $_POST['couponcode']; }
Code:
$insert_query = sprintf("INSERT INTO BagTags (personalizedname, personalizedaddress, personalizedphone, mountain, surfboards, bird, sailboats, beach, name, company, address1, address2, citystatezip, phone, email, asippaiupicid, comments, mailingbrochureoffer, emailoffer, tradeshowoffer, otheroffer, othertext, couponcode) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 'CompanyA', %s, %s, %s, %s, %s, %s, %s)", sanitize($personalizedname, "text"), sanitize($personalizedaddress, "text"), sanitize($personalizedphone, "int"), $mountain, $surfboards, $bird, $sailboats, $beach, sanitize($name, "text"), sanitize($company, "text"), sanitize($address1, "text"), sanitize($address2, "text"), sanitize($citystatezip, "text"), sanitize($phone, "int"), sanitize($email, "text"), sanitize($comments, "text"), //sanitize($type, "text"), $mailingbrochureoffer, $emailoffer, $tradeshowoffer, $otheroffer, sanitize($othertext, "text"), $couponcode);
Comment