Category Archives: Php

How to submit multiple checkbox values with php

Hello World, Welcome to ProjectsPlaza.com. Today we will learn how to submit and print multiple checkbox values with PHP. I have divided this tutorial into the following parts.
  • Create a form with multiple checkboxes
  • Submit the form with PHP and print the values

Create a form with multiple checkboxes

  • Create a form.php file and add the following in this.
  • <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Submit Checkbox Values with Php</title>
    </head>
    <body>
        <h3>Select Your Favorite Fruits</h3>
        <form action="" method="post">
            <ol>
                <li>
                    <input type="checkbox" name="fruit[]" value="apple" id="apple" />
                    <label for="apple">Apple</label>
                </li>
                <li>
                    <input type="checkbox" name="fruit[]" value="banana" id="banana" />
                    <label for="banana">Banana</label>
                </li>
                <li>
                    <input type="checkbox" name="fruit[]" value="grapes" id="grapes" />
                    <label for="grapes">Grapes</label>
                </li>
                <li>
                    <input type="checkbox" name="fruit[]" value="kivy" id="kivy" />
                    <label for="kivy">Kivy</label>
                </li>
            </ol>
            <input type="submit" name="submit" />
        </form>
    </body>
    </html>
  • You have noticed that we have added checkbox name as an array, It will store the value in array form. This is the important step. Once you added the values as array form, It will very easy to print the data.


Submit the form with PHP and print the values

Add the following code at the top of file form.php
<?php
if(isset($_POST['submit'])){
    $fruits=$_POST['fruit'];
    echo '<pre>';
    print_r($fruits);
    echo '</pre>';
}
?>

How to save error logs in file in Codeigniter 3

Hello World, Welcome to ProjectsPlaza.com. Today I am going to discuss how to save error logs in the file in Codeigniter 3. Sometimes we need to save the errors in our development process. We can do this with a very easy step.

  • Open application/config.php
/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
|   0 = Disables logging, Error logging TURNED OFF
|   1 = Error Messages (including PHP errors)
|   2 = Debug Messages
|   3 = Informational Messages
|   4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
|   array(2) = Debug Messages, without Error Messages
|
| For a live site, you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 1;

You can change the above threshold according to the requirements. They have defined all options.


It will save the error in the application/logs directory.

Make sure your logs directory has writable permission

9 Useful Php Array Functions

Hello World, In this article, we will discuss 9 Useful Php Array Functions. I will discuss some functions in some detail and with an example. Following are some steps are given below to run the array function.


print_r()

This function is used to print an array with its key and value. this function read like key automatically  0=>ram 1=>sham etc. but we can define our custom key like ram=>age ram=>DOB etc. In this, ram is key and age and DOB is its value.

<?php
$a= ['ram','sham','geeta'];
print_r ($a);
?>
//Output:
//Array ( [0] => ram [1] => sham [2] => geeta )

explode()

This function is used to convert a string into an array. we can use value and variable names to explode the string.

<?php
$a= "it is string";
print_r (explode(" ",$a));
?>
//Output: Array ( [0] => it [1] => is [2] => string )

implode()

This function is used to convert the array into a string. we can use value and variable name to implode the array.

<?php
$a= ['ram','is','a','good','boy.'];
print_r (implode(" ",$a));
?>
//Output:  ram is a good boy

sort()

This function is sort array in ascending order by its value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
sort($name);
print_r ($name);
'</pre>';
?>
Output: 
 Array
(
    [0] => geeta
    [1] => ram
    [2] => sham
    [3] => sita
)

asort()

This function is to sort the array’s value in ascending order. In this function, the key is set according to the array’s value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [2] => geeta
    [0] => ram
    [1] => sham
    [3] => sita
)

ksort()

This function is a short array’s key in ascending order. In this function, the value is set according to the array’s key.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [0] => ram
    [1] => sham
    [2] => geeta
    [3] => sita
)

rsort()

This function is sort array in descending order.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
sort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [0] => sita
    [1] => sham
    [2] => ram
    [3] => geeta
)

arsort()

This function is a short array’s value in descending order. In this function, the key is set according to the array’s value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [3] => sita
    [1] => sham
    [0] => ram
    [2] => geeta
)

krsort()

This function is a short array’s key in descending order. In this function, the value is set according to the array’s key.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [3] => sita
    [2] => geeta
    [1] => sham
    [0] => ram
)
create-comment-system-with-jquery-ajax-and-laravel-7

Create comment system with jquery ajax and laravel 7

Hello World, Welcome to ProjectsPlaza.com. Today we will learn how to create a comment system with jQuery Ajax and Laravel 7. In this tutorial, we will save comments and show instantly with the total comments count. This gonna be a very interesting tutorial for me as well as for you (I hope). I have divided this tutorial into the following parts:

  • Create a Post model
  • Create a Comment model
  • Define the hasMany relationship in Post Model
  • Add dummy data for post
  • Create a PostController and define a method for post list and post detail
  • Create templates for post and post detail with comments and show data
  • Setup route
  • Add a comment with jquery ajax and  show instantly

Continue reading

How to create website without coding knowledge

Hello World, Today I am going to create a website without coding knowledge. You just need basic knowledge of internet browsing. In this tutorial, we will create a beautiful blog website with WordPress without coding experience. I have divided this tutorial into three parts.

  • Introduction of WordPress
  • How to download and install WordPress.
  • Create and run the website

Continue reading

How to integrate stripe payment with laravel 7

Hello World, Welcome to projectsplaza.com. Today i am going to create a tutorial about stripe payment with laravel 7. This is a small and very easy tutorial. It is very easy to integrate stripe with laravel. I have divided this tutorial into the following parts.

  • Setup stripe account
  • Install stripe package in laravel
  • Integrate stripe with laravel
  • Make payment

Continue reading

How to create api with laravel 5

Hello World, Welcome to my website. Today I will discuss how to create API with laravel 5. Laravel provides a very efficient way to create API with its resource controller which are already structured around REST verbs and patterns. In this tutorial, we will create a simple example to better understand APIs.

I am using laravel 5.8

I have divided this tutorial into the following parts.

  • Create Resource Controller
  • Create Modal
  • Access Data via Resource Controller
  • API Routing
  • Test API in Postman

Continue reading

How to use database migration in laravel

Hello World, Welcome to my website. Today I am going to discuss how to use database migration in laravel. For a better understanding of database migration, I have created this tutorial with example.

I have divided this tutorial into the following parts.

  • What is migration?
  • How to Create a migration file?
  • How to Run Migration?

Continue reading