How to insert single checkbox value in database using laravel?

Here we using 2 file for insert multiple checkbox value:

  • index.php HTML form that that allows user to select option from the checkbox.
  • process.php For process the user data.

index.php





I have a bike

I have a Cycle
I have a car

process.php

" . mysqli_error[$conn];
}
mysqli_close[$conn];
?>

Show Demo

report this ad
report this ad

It's really not a table issue. I also tried this:

	    @foreach[$version->of_show->has_credits as $credit]
    	
			
  • {{ $credit->display_name }} [{{ $credit->role_name }}]
  • @endforeach

    With this being the controller:

    	$credits = Input::get['credit'];
    	$role_id = Input::get['role_id'];
    	$biography_id = Input::get['biography_id'];
    	$bio_name_id = Input::get['bio_name_id'];
    	$version_id = Input::get['version_id'];
    	
    	foreach [$credits as $credit_id]
    	{
            DB::insert['INSERT INTO version_authors [credit_id, version_id, role_id, biography_id, bio_name_id] VALUES [?,?]', array[$credit_id, $version_id, $role_id, $biography_id, $bio_name_id]];
        }
    

    It gave me the error:

    preg_replace[]: Parameter mismatch, pattern is a string while replacement is an array
    

    So, as you can see. It's trying to get multiple columns copied instead of just one.

    In this post we will see how to store multiple checkbox value in database using laravel. Whenever you want to save multiple checkbox value in the single column in database at that time this example will help to solve your query.

    Here we will store checkbox value and insert multiple checkbox value in database and also we will see how to retrive multiple checked checkbox value.

    Step 1 : Install Laravel 8 and Setup Configuration for Store Multiple Checkbox Value in Database

    Step 2 : Create Model and Migartion Table for Save Multiple Checkbox Value

    Step 3 : Create Route

    Step 4 : Create Controler

    Step 5 : Create Blade File

    Step 1 : Install Laravel 8 and Setup Configuration for Store Multiple Checkbox Value in Database

     Install laravel application and set database configration as per your requirment.

    Step 2 : Create Model and Migartion Table for Save Multiple Checkbox Value

    Now, we will create database migration for posts table and Post Model using artisan command in laravel.

    php artisan make:model Post -m

    After that add below code in your post migration file in  this path /database/migrations/2021_05_14_103523_create_posts_table.php

    In this post we will see how to store multiple checkbox value in database using laravel. Whenever you want to save multiple checkbox value in the single column in database at that time this example will help to solve your query.

    Here we will store checkbox value and insert multiple checkbox value in database and also we will see how to retrieve multiple checked checkbox value.

    In this article i will share with you how to store multiple checkbox value in database in laravel application with example.

    In this tutorial, I will utilize multiple checkbox value stores in the database used

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=dbjson
    DB_USERNAME=root
    DB_PASSWORD=secret
    3 and
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=dbjson
    DB_USERNAME=root
    DB_PASSWORD=secret
    4. Insert data JSON encode value and get data to JSON decode in laravel app.

    I will give you a full example for store multiple checkbox values in the database utilizing laravel.So let's follow the bellow step by step.

    Step 1 : Install Laravel

    In this step, You will install laravel fresh application So open the terminal and put the bellow command.

    composer create-project --prefer-dist laravel/laravel blog
    

    Step 2 : Setup Database Configuration

    After successfully install laravel app then after configure database setup. We will open the "

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=dbjson
    DB_USERNAME=root
    DB_PASSWORD=secret
    5" file and change the database name, username and password in the env file.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=dbjson
    DB_USERNAME=root
    DB_PASSWORD=secret

    Step 3 : Create Table Migration and Model

    In this step, we have to create a migration for posts table and Post Model using Laravel php artisan command, So open terminal and put the bellow command.

    php artisan make:model Post -m
    

    After this command, you have to put below code in your migration file to create the posts table.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=dbjson
    DB_USERNAME=root
    DB_PASSWORD=secret
    6

    Bài mới nhất

    Chủ Đề