PHP - Delete Multiple Row To SQLite Using PDO

In this tutorial we will create a Delete Multiple Row To SQLite Using PDO. PHP is a server-side scripting language designed primarily for web development. SQLite provides an interface for accessing the database. It includes class interfaces to the SQL commands. And also it allows you to create SQL functions and aggregate using PHP. So Let's do the coding...

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the jquery that i used in this tutorial https://jquery.com/. Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. Installing SQLite Browser We will now then install the SQLite data viewer, here's the link for the DB Browser for SQLite http://sqlitebrowser.org/.

Setting Up SQLite

First, we are going to enable SQLite 3 in our PHP. 1. Open localhost server folder XAMPP, etc and locate php.ini. 2. Open php.ini and enable sqlite3 by removing the semicolon in the line. tut1 3. Save changes and Restart Server.

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php. setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = "CREATE TABLE IF NOT EXISTS student(student_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, student_no INTEGER, firstname TEXT, lastname TEXT, address TEXT)"; $conn->exec($query); ?>

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.

PHP - Delete Multiple Row To SQLite Using PDO




prepare("SELECT * FROM `student` ORDER BY `lastname` ASC"); $query->execute(); $count_query = $conn->prepare("SELECT COUNT(*) as count FROM `student` ORDER BY `lastname` ASC"); $count_query->execute(); $row = $count_query->fetch(); $count = $row['count']; while($fetch = $query->fetch()){ ?>
Select All Student No Firstname Lastname Address

Creating the PHP Query

This code contains the php query of the application. This code will store the data inputs to the SQLite database Using PDO prepare statement. To do this just copy and write these block of codes as shown below inside the text editor and save it as save_student.php. prepare($query); $stmt->bindParam(':student_no', $student_no); $stmt->bindParam(':firstname', $firstname); $stmt->bindParam(':lastname', $lastname); $stmt->bindParam(':address', $address); $stmt->execute(); $conn = null; header('location: index.php'); } ?>

Creating the Script

This code contains the script of the application. This code will count the checkboxes that will be remove by the user. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder. function selectedCheckbox(check){ var checkboxes = document.getElementsByName('check[]'); for(var i in checkboxes){ checkboxes[i].checked = check.checked; } var count = document.querySelectorAll('input[name="check[]"]:checked').length; document.getElementById('count').innerHTML = count; } function countCheckbox(){ var count = document.querySelectorAll('input[name="check[]"]:checked').length; document.getElementById('count').innerHTML = count; }

Creating the Main Function

This code contains the main function of the application. This code will delete the data from the database base on the checked item in the row. To do this just copy and write these block of codes as shown below inside the text editor, then save it as delete.php. prepare($query); $stmt->bindParam(':student_id', $id); $stmt->execute(); } $conn = null; header('location:index.php'); }else{ echo ""; echo ""; } } ?> There you have it we successfully created a Delete Multiple Row To SQLite Using PDO. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Comments

Submitted byNjabulo Treasure (not verified)on Wed, 10/10/2018 - 22:17

Nice Project I really like it

Add new comment