Category: PHP

Remember me option allow the user to automatically get logged in to the website without entering its username and password again.

To do this I am using $_COOKIE which store value on the client side for detecting the user. Next time when the user come it will automatically redirect to the homepage.

Encrypt the value before storing it in $_COOKIE and decrypt it while access. It will automatically destroy after 30 days.

Login page with Remember me in PHP

PHP

The Pdf file creation in PHP mainly requires when we need to generate the file on the basis of the available data otherwise, we simply create it manually with the external applications.

For example – generating the report, the user certificate, etc.

For generating pdf file I am using Dompdf library which generates the downloadable pdf file from HTML.

Generate Pdf from HTML with Dompdf in PHP

PHP

This usually occurs when the user already submitted data and tries to refresh the page. In this case, the browser will attempt to POST the page again.

If you do not perform any action then a new duplicate record inserted on the MySQL Database table.

In this tutorial, I show some of the ways which you can use to avoid it.

Prevent page from submit on refresh in PHP

AJAX Jquery PHP

The checkbox element in HTML allows us to select multiple items from the group of values.

When you use it in your form and try to read all checked values as any other elements like –  text box, text area, radio button etc.

echo $_POST['lang'];  // Checkbox element

you will get the last checked value.

You need to send the checkboxes value in the form of an Array when the form gets submitted then you can loop over $_POST values.

Get checked Checkboxes value with PHP

PHP

The break statement is used to ends the execution of the current loop or switch case statement in PHP.

But when working with nested loops and wants to exit out from all or some of the outer loops. For this, you need to pass numeric value following with break statement.

In this tutorial, I show how to out from two inner loops and n number of nested loop.

How to Break the nested loop in PHP

PHP

There is the various approach of selecting the last insert id from MySQL table.

  • Select a single row from the table in descending order and store the id.
  • Select Maximum value.
  • The following query gives you next AUTO_INCREMENT value from selected table which you can use to get the last id.
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'user'

If your currently AUTO_INCREMENT column last value is 8 and when you execute the above query on the Table this will return 9.

In PHP there is an inbuilt method which simply returns the last insert id according to the previous insert query.

Get last insert id from MySQL Table with PHP

DataBase PHP

In PHP, it is possible to upload multiple files using single input file element. You just need to customize your single file upload PHP code and enable your file element to select multiple files.

In this tutorial, I show you how to implement multiple files upload with PHP.

Multiple files upload at once with PHP

PHP

When you have the large collection of images files on a directory and you wants to convert it into the photo gallery.

Solution 1

Add image file manually to your page one by one which you want to show. The problem with this solution is it is time-consuming and you have to check all image links if any update in future.

Solution 2

Store image names in the Database table and use it to get images.

Solution 3

Read all files from target directory and generate photo gallery.

The second and third solution are better but in this post, I will show you how to implement the third solution with PHP.

How to make photo gallery from image directory with PHP

How To PHP

Pagination is a technique to break and display the large list of content in the smaller parts. This reduces your page load time and it is user-friendly.

There are multiple types of pagination available some are –

In this tutorial, I show How you can add numeric pagination to your web page.

How to make PHP numeric pagination

DataBase PHP

There are many things you can do with AJAX to improve the user experience, for example, Add, edit or delete the record and update layout without reloading the page.

Deleting record only using PHP

If you have never used AJAX for deleting before then you either passing the id with $_GET or $_POST methods. Deleting the record when the value is get set.

This works and removes the record but it reloads the page every time.

In this tutorial, I show you How to remove the record from MySQL Table with jQuery AJAX.

What in the demonstration ?

In the demonstration, I am creating the HTML table which shows the list of records with a delete button. When the button gets clicked then removing record and HTML table row with fadeOut() effect.

How to Delete Record from MySQL Table with AJAX

AJAX Jquery PHP