Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:05:50+00:00 2026-05-22T22:05:50+00:00

MySQL `field1` tinyint(1) NOT NULL default ‘1’, `field2` tinyint(1) NOT NULL default ‘1’, `field3`

  • 0

MySQL

`field1` tinyint(1) NOT NULL default '1',
`field2` tinyint(1) NOT NULL default '1',
`field3` tinyint(1) NOT NULL default '1',
`field4` tinyint(1) NOT NULL default '1',
`field5` tinyint(1) NOT NULL default '1',

HTML

<form method="post">
<input type="hidden" name="blah" value="blah">

<input type="checkbox" name="field1" value="1">
<input type="checkbox" name="field2" value="1">
<input type="checkbox" name="field3" value="1">
<input type="checkbox" name="field4" value="1">
<input type="checkbox" name="field5" value="1">

<button type="submit">Submit</button>

</form>

PHP

mysql_query("UPDATE `table` SET `field1` = '$_POST[field1]', .......");

So, what I want to do is:

a) If the checkbox is checked, I want to update the appropriate field with 1

b) If the checkbox is unchecked, I want to update the field with 0

And now, please tell me I don’t have to do it like this and that there is a nicer way of doing it:

$field1 = isset($_POST['field1']) ? 1 : 0;
$field2 = isset($_POST['field2']) ? 1 : 0;
$field3 = isset($_POST['field3']) ? 1 : 0;
$field4 = isset($_POST['field4']) ? 1 : 0;
$field5 = isset($_POST['field5']) ? 1 : 0;

mysql_query("UPDATE `table` SET `field1` = '$field1', `field2` = '$field2' ....");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:05:51+00:00Added an answer on May 22, 2026 at 10:05 pm

    You can use field[]

    <input type="checkbox" name="field[0]" value="1">
    <input type="checkbox" name="field[1]" value="1">
    

    So you can do a simple loop:

    for($i=0;$i<5;$i++)
       $field[$i] = isset($_POST['field'][$i]) ? 1 : 0;
    

    And then build your SQL

    If you want to skip the isset Part you could use a radio type, so You have always or the 1 value or 0 value setted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PDO to insert a record (mysql and php) $stmt->bindParam(':field1', $field1, PDO::PARAM_STR); $stmt->bindParam(':field2',
assume I already created a table in MySQL as below CREATE TABLE IF NOT
This MySQL query is failing and i just can not figure out why. Any
I have problem in creating tinyint field in MySQL database using Hibernate. I used
Difference between TinyInt / SmallInt / MediumInt / Int / BigInt in MySQL data
I have a MySQL database which currently uses a tinyint field to store the
I am using a simple HTML checkbox in a form to put a 1
I need to reset a MySQL Field value automatically at midnight. It is a
I'm trying to replace a bunch of characters in a MySQL field. I know
I am trying to store a json encoded array into a MySQL field. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.