본문 바로가기

카테고리 없음

Php Mysql Multiple Checkbox Update Safari



  1. Checkbox Update
  2. Mysql Update Multiple Columns
  3. Mysql Update Set Multiple Columns

Apr 15, 2018  In this tutorial you will see how we can update the multiple checkbox values and save them to Mysql Database. In this video we have created the List of Checked Checkbox using saved values from the.

Active15 days ago

I cant seem to find or figure out a working solution to insert multiple checkbox values from a form into a table. The closes I have come is inserting the value of merely one checkbox value into a table. Kindly point out how I can insert multiple checkbox values and not merely one.

Find below what I have so far:

My form:

My php file to read and insert the values into a table:

  • Updating MySQL table with PHP and checkboxes. Ask Question. Up vote 1 down vote favorite. I have a table called products, with an. Insert into a MySQL table or update if exists. Why shouldn't I use mysql_* functions in PHP? Hot Network Questions My friends and I went snowboarding.
  • I have a script to update multiple rows in database but it update [B]all[/B] and I need to [B]only.
Mohit Kumar
8732 gold badges4 silver badges18 bronze badges
SirBTSirBT
5353 gold badges12 silver badges31 bronze badges

3 Answers

You should specify

as array.

Add [] to all names Days and work at php with this like an array.

After it, you can INSERT values at different columns at db, or use implode and save values into one column.

Didn't tested it, but you can try like this. Don't forget to replace mysql with mysqli.

Viacheslav KondratiukViacheslav Kondratiuk
4,0667 gold badges37 silver badges72 bronze badges

You need to declare the array in the HTML via

Also you can insert multiple items with one query like this

Also keep in mind that mysql_* functions are officially deprecated and hence should not be used in new code. You can use PDO or MySQLi instead. See this answer on SO for more information.

kerokero
10.2k5 gold badges34 silver badges43 bronze badges
Drudge RajenDrudge Rajen
3,5322 gold badges16 silver badges37 bronze badges

Not the answer you're looking for? Browse other questions tagged phpmysqlcheckboxmultipleselection or ask your own question.

Active2 years, 11 months ago

I want to have multiple checkbox values be stored into one field in a database. (Ex. 1, 24,56,100). I am wanting to know how I can make this happen, and how does PHP read these values from the database if I want to call variables in a query?

Basically I am creating a blog app (for fun and experience) and I want the user to be able to change the visibility of each blog post through checkboxes. I know you are probably thinking why don't I just have a visibility field for each blog post. I understand why it is not recommended to do this, but I can't think of any other way to do this. To explain a bit more: I want to attach this application to a CMS I have already built, and basically I have a table with blog posts, and then I want the user to be able to go to different pages within their site and add a blog. Well, what if the user wants to use the same blog on 3 different pages, but only wants certain posts to show on each page. So this is why I am confused right now.

Charles
46.5k12 gold badges90 silver badges127 bronze badges
drummer392drummer392
1682 gold badges5 silver badges32 bronze badges

4 Answers

Even though I am not in favor of saving data like that but here is what you can do, if you really want to do it that way. I suggest you have a denormalized table and store your vals there

in your HTML you can have your checkboxes like this (considering you are storing ids of some sort)

Checkbox Update

On you php side you can use function implode to form ids into a string as shown below (considering you are doing a POST)

Where you read from the database you can transform the value from db to an array like this

I hope this helps

Jaspreet ChahalJaspreet Chahal
2,6301 gold badge11 silver badges17 bronze badges

first create database:

after that create an html page like that:

after that we have do mysql connect.php

after that we have to create an check.php like that ok

Safarikleopatra
45.9k16 gold badges76 silver badges168 bronze badges
srisri

The perfect solution for this is task the creation of normalized table as commented by @OMG and @Michael.

But here is the answer for what you just asked

Store this in MySQL table. You can use LIKE command to query the table and use the explode to get back the ids in array.

Rohan Kumar
36k11 gold badges63 silver badges95 bronze badges
Alex JoseAlex Jose

You're going to want to go through the basics of PHP and MySQL.

Check out tizag.com or w3schools.com, or some other sites (the tutorials are plentiful).

Here's the basics though--and remember this, as it'll help you in your understanding.

MySQL is a database. A database is typically used for storing data.PHP is a programming language. It's typically used for programming.

So, some wonderful developers out there have already taken care of the steps for talking to the database from PHP. All you have to do is establish a connection.

See mysql_connect via W3Schools

Okay, so what you have done here, is you've connected to the database SERVER. You haven't selected a database yet. Think of it like going to a movie theater, you still have to pick a movie to watch.

So, now we connect to our database:

Mysql Update Multiple Columns

See mysql_select_db via W3Schools

Once you've connected to your database, you're ready to grab some information from it.
To do this, you need to create your SQL query.

Something to the tune of:

See the SELECT statement via W3Schools

Depending on how your table is set up, that will get you the list for the current user. I'm assuming that you already have the user's id (or a way to get it), since they have the ability to define their own preferences for the site.

Now that you have the SQL query to get the articles, you need to query the database.

That should get you your list of ID's that you need.

I'll let you figure out the rest. It's pretty straight-forward, and you've got all of the tools that you need now. The only thing you might want to brush up on is explode and foreach.

So, the way you store them is up to you. Look into explode for splitting them up when they're stored that way.

Tim

Mysql Update Set Multiple Columns

Tim
2,8863 gold badges17 silver badges41 bronze badges

Not the answer you're looking for? Browse other questions tagged phpmysqldenormalized or ask your own question.