Get Last insert id from MySQL Table with PHP

There are various approaches to selecting the last insert ID from the MySQL table:

  • Fetch the ID by selecting a row in descending order and storing the ID.
  • Retrieve the maximum value.
  • The query below provides the subsequent AUTO_INCREMENT value for the chosen table, useful for acquiring the last ID.
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'user'

For example, if your AUTO_INCREMENT column’s last value is 8, executing the query will return 9.

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

Get Last insert id from MySQL Table with PHP

Read more

Multiple files upload at once with PHP

Whether you’re creating a file-sharing platform, a social media website, or any other type of web application, the ability to upload multiple files at once can significantly improve user experience.

In PHP, it is possible to upload multiple files using a 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 validation in PHP.

Multiple files upload at once with PHP

Read more

How to make Photo Gallery from image Directory with PHP

Are you faced with the task of organizing a large collection of image files into a visually appealing PHP photo gallery? There are the following solutions that you can use:

Solution 1:
One approach to creating a photo gallery is to manually add each image file to your web page individually. However, this method proves to be time-consuming and cumbersome, as it requires constant monitoring for any future updates to the image links.

Solution 2:
Another option involves storing the image names in a Database table and retrieving them when needed. This solution offers more efficiency and flexibility compared to the previous one.

Solution 3:
However, the most optimal solution involves reading all the files from your designated directory and generating an automated photo gallery. This approach eliminates the need for manual intervention and ensures that any changes or additions to the image directory are automatically reflected in the gallery.

In this post, I will focus on demonstrating the implementation of the third solution, utilizing the power of PHP. By following this guide, you will be able to create a dynamic and seamless photo gallery effortlessly.

So, without further ado, let’s dive into the exciting world of PHP photo galleries and discover how you can transform your image directory into an engaging visual experience!

How to make Photo Gallery from image Directory with PHP

Read more

How to Delete Record from MySQL Table with AJAX

There are many ways AJAX can enhance user experience, such as adding, editing, or deleting records without reloading the page. With only PHP, deleting records often involves submitting the page or sending values via URL, resulting in page reloads with each deletion.

However, jQuery AJAX offers a more seamless solution. By passing the record ID via AJAX, you can delete records without reloading the page.

In the example, I’m creating an HTML table displaying a list of records with a delete button. Upon button click, the corresponding record is removed, and the HTML table row fades out as an effect.

How to Delete Record from MySQL Table with AJAX

Read more