Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am creating a form below - in which inserts into MYSQL database if the checkbox is checked as TRUE or FALSE (BOOLEAN)

I have the below but I'm not sure how I can get it into the database?

What I have tried:

<h1>Question 1</h1><br>
 </br>
  <input type="checkbox" name="B1" value="">Milk
  <input type="checkbox" name="B2" value="">Cheese
  <input type="checkbox" name="B3" value="" >Yogurt
  <input type="checkbox" name="B4" value="">Eggs
  <input type="checkbox" name="B5" value="">Beans
Posted
Updated 14-Mar-18 0:26am

1 solution

You have to send the form data to a PHP script (see PHP: Dealing with Forms - Manual[^]).

Within your PHP script read the data as described in the above link and act accordingly. For database access use PHP: MySQLi - Manual[^].

[EDIT]
To determine the state of a checkbox, check if the corresponding data is set:
PHP
$b1 = FALSE;
if (isset($_POST['B1'])) {
    $b1 = TRUE;
}
[/EDIT]
 
Share this answer
 
v2
Comments
Member 13637584 14-Mar-18 6:31am    
i understand how to put the values into MYSQL database, as I've created a registration page previously, it's how to insert into the database FALSE if box is not checked and TRUE if box is checked?
Jochen Arndt 14-Mar-18 6:42am    
That can't be answered without knowing the design of your database and what you finally wnat to do.

If a table contains BOOLEAN fields you just have to set those fields accordingly.

It is also not clear from your question if you want set BOOLEAN values in your database or use the values to decide what should happen (e.g. create a new recordset, or update an existing one).

Please be aware that we don't have access to your data (existing code, database design) and can't read your mind (what you finally want to do).

You can use the green 'Improve question' link to add more information.
Member 13637584 14-Mar-18 6:45am    
Simply put, all i want to do is from those checkboxes above - (B1,B2,B3,B4 etc) which is in the database, if the user, for example, checks B1 & B3 - i want to insert into database, showing B1 and B3 as 1 and rest 0?
Jochen Arndt 14-Mar-18 6:58am    
See my updated answer. But I still can't give more help without additional information.

Inserting into a database is creating a new recordset within a table. The general SQL syntax is:
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
So you have to create a corresponding SQL query string and execute that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900