This tutorial tackles on how to CRUD(create, read, update, delete) MySQL database using PDO with Bootstrap/Modal. PDO as per the PHP manual stands for PHP Data Objects, a lightweight, consistent interface for accessing databases in PHP. We use Bootstrap/Modal in this tutorial to handle our forms.
Getting Started
I've used bootstrap and jQuery in this tutorial to enable bootstrap modals. These files are included in the downloadable of this tutorial but, if you want, you may download them using the links below:
I've included a .sql file in the downloadable of this tutorial which is a mysql database file. All you have to do is import the said file. If you have no idea on how to do this, please refer to my tutorial, How import .sql file to restore MySQL database.
You should be able to create a database with tables named mydatabase.
Creating our Connection
Next, we create a connection to our database by creating a new file, name it as connection.php and paste the codes below.
echo"There is some problem in connection: ".$e->getMessage();
}
}
publicfunction close(){
$this->conn=null;
}
}
?>
In here, we have created a class named Connection and we are going to include this file and create a new object for our connection if we want to connect to our database.
Displaying our Data
Next, we are going to display that data in our table by creating a new file, name it as our index.php and paste the below codes.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PHP CRUD Operation using PDO with Bootstrap/Modal</title>
That ends this tutorial. I hope this will help you and you have learn something usefull with this tutorial. You can download my sample source code that I have created for this tutorial by clicking the Download button below. Explore more in this website for more tutorials and Free project source codes.
Happy Coding :)
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Hello, first of all, great tutorial!
I want to use the Modal CRUD for my website, but I have MSSQL Server, not MYSQL, but this should not be a problem.
I have made a Modal with taps, in the first tab there will be shown general information, in the second one there will be a kind of chat. I can open the modal, can select the tabs, I can see the right entries but I have a problem to add a new chat entry. This is my add.php:
include_once'dbconfig.php';
$message=$_POST['message'];
$regid=$_POST["reqid"];
try
{
$stmt=$DB_con->prepare("INSERT INTO dbo.RequestChat (ReqID, message) VALUES (:id, :message)");
$stmt->bindParam(':id',$regid);
$stmt->bindParam(':message',$message);
$stmt->execute();
returntrue;
}
catch(PDOException $e)
{
echo$e->getMessage();
returnfalse;
}
I have added this code to my index.php to test the add function, it works, it seems that there is something missing in the modal or in the add.php, so the values can nit been written in the database.
Do you have an idea why I can not add something in the database.
BR Sven
Hi there, first of all, great Tutorial,
I want to use CRUD with Modal in my website, but I have a problem to add new entries in my database. I am using MSSQL, here is my add.php:
include_once'dbconfig.php';
$message=$_POST['message'];
$regid=$_POST["reqid"];
try
{
$stmt=$DB_con->prepare("INSERT INTO dbo.RequestChat (ReqID, message) VALUES (:id, :message)");
$stmt->bindParam(':id',$regid);
$stmt->bindParam(':message',$message);
$stmt->execute();
returntrue;
}
catch(PDOException $e)
{
echo$e->getMessage();
returnfalse;
}
I have tested this code in my index.php, it works like a charm. but when I use it like in your Tutorial, I can not add a new entry in the database.
Do you have an idea where my failure is?
BR
Sven
Hi there, firat of all, very coot tutorial!
I want to use CRUD with Modal and MSSQL, but I have a problem by adding a new entry in MSSQL Database, my add.php loosk like:
include_once'dbconfig.php';
$message=$_POST['message'];
$regid=$_POST["reqid"];
try
{
$stmt=$DB_con->prepare("INSERT INTO dbo.RequestChat (ReqID, message) VALUES (:id, :message)");
$stmt->bindParam(':id',$regid);
$stmt->bindParam(':message',$message);
$stmt->execute();
returntrue;
}
catch(PDOException $e)
{
echo$e->getMessage();
returnfalse;
}
Do you have am idea why i can not add something in the database?
BR
Sven