Loading.......
Loading...

Update or Delete Multiple Rows using PHP

Posted on 25th October, 2025
PHP DATA INSERTION PHP UPDATE ROWS PHP DELETE DATA
This tutorial teaches you how to implement a simple update or delete multiple rows or user details in or from the database using PHP.

To select or identify multiple rows of user details, we have used check boxes and passed the ID of each user which were brought from the database to the check box assigned to each user in a html form.

To submit the selected check boxes which holds the ID of each user detail for an update or deletion purpose, javascript is used for redirection to the pages with the scripts that performs the actions needed for each operation.

The purpose of this tutorial is to show how a simple script can be written using PHP to update multiple rows of data brought from the database or delete the data from the database. You will be able to add additional requirements to the script by following what has been done if needed.

DATABASE CONNECTION SCRIPT

<?php
/**
 * These are the database connection details
 */  
 
define("HOST", 'localhost');     // The host you want to connect to.
define("USER", 'root');    		// The database username. 
define("PASSWORD", '');    		// The database password. 
define("DATABASE", 'demo');    	// The database name.

$mysqli = mysqli_connect(HOST, USER, PASSWORD) or die("Unable to connect to MySQL Server: ". mysqli_connect_error());
mysqli_select_db($mysqli, DATABASE) or die("Unable to connect to Database: ". DATABASE);
?>


UPDATE MULTIPLE ROWS SCRIPT

<?php
include "config.php";
if(isset($_POST["userId"]) && trim($_POST["userId"]) != "") 
{
	$vpb_counted_users = count($_POST["userId"]);
	
	for($i=0; $i<$vpb_counted_users; $i++) 
	{
		ob_start();
		
		mysqli_query($mysqli,"update `updated_users_demo` set `firstname` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["firstname"][$i])))."', `lastname` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["lastname"][$i])))."', `username` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["username"][$i])))."', `password` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["password"][$i])))."' where `id` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["userId"][$i])))."'");
		
		ob_end_flush();
	}
}
?>


DELETE MULTIPLE ROWS SCRIPT

<?php
include "config.php";

// THE CODE BELOW DELETES THE ROWS SELECTED BY THE USER AFTER CONFIRMING TO DELETE THEM AND REDIRECTS BACK TO THE index.php
if( isset($_POST["users"]) && !empty($_POST["users"]) ) 
{
	for($i=0; $i<$selected_users_id; $i++) 
	{
		ob_start();
		// Delete selected rows from the database
		mysqli_query($mysqli,"delete from `updated_users_demo` where `id` = '".mysqli_real_escape_string($mysqli,trim(strip_tags($_POST["users"][$i])))."'");
		ob_end_flush();
	}
	header("location: index.php"); // REDIRECTS BACK TO THE index.php
	exit();
}
?>

There is a README.txt file in the downloaded folder that gives you information on how to install the system.

This is a very simple to understand application as all you need to do are well explained in the script.

The script is very easy to understand and customize with well written codes to ease usability.

To see the system in action, please click on the live demo button below and download the script if you like what you see.
Post Comment
Press Enter to send
No comment yet.


Popular Tutorials Pagination System using Ajax, Jquery and PHPSend Friend Request, Accept or Decline Request using Ajax, Jquery and PHPContact Form with Captcha using Ajax, Jquery and PHPWhy Having a FREE website is bad ChoiceBulk image resize with PHPWeb Browser Notification System using JavaScriptIntroduction to php.ini FileTypes of PHP ErrorsProgram Execution Time Limit in PHPTo-do list using PHP and MySQLiMove File from One Folder to the other using PHPHow to change or convert MySQL to MySQLiHow to Upload Video Files using PHP and MySQLiConvert HTML to MS Word Document using PHPEight Reasons Why You Need A Business WebsiteLocal Web Development Server for Windows - XAMPPEasy Shopping Cart using HTML, CSS & JavaScriptComment System using PHP, Ajax and MySQLiAdd, Edit and Delete Record from Database using jQuery and PHPResponsive Contact Form with Captcha using Jquery and PHPUpdate or Delete Multiple Rows using PHPPassword Strength Checker using JqueryFacebook Style Auto Scroll Pagination using jQuery and PHPDomain Checker using Ajax, Jquery and PHPThe if else & elseif Statements in PHPPreview and upload multiple files using ajax and PHPFancy Multiple File Upload using Ajax, Jquery and PHPPagination System without Database using Ajax and PHPUnderstanding Cookies in JavaScript: Create, Read, Update and DeleteSecured Users Access Level System using PHP and MysqlSecure Forgot Password System Using Ajax, Jquery and PHPChat Script Similar to Facebook using Ajax and PHPMake Dynamic XML sitemap using PHPHow to create an animated old letter using an animated penAuto-load User Details on Mouse-Over using Ajax, Jquery and PHPFacebook style Search People and Products using Ajax, Jquery and PHPAuto-suggestion using Ajax and PHPAuto-suggest System using Ajax, Jquery and PHPUsername Availability Checker using Ajax and PHPSimple PHP Anti-Spam Captcha Contact Form Submission

Submit your Job or Project Today!

We can help you turn your idea into reality, take over your existing project, or extend your current development team.

Submit your idea job or project below and we will follow up with you shortly.

OUR OBJECTIVE

Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.

OUR MISSION

We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.

Please Wait....
Please Wait...