<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>crud operation Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/crud-operation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/crud-operation/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Fri, 05 May 2023 01:21:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>CRUD operation using PHP Bootstrap 5 &#038; MySQL</title>
		<link>https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/</link>
					<comments>https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Fri, 05 May 2023 01:21:33 +0000</pubDate>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[crud operation]]></category>
		<category><![CDATA[CRUD operation using PHP Bootstrap 5 & MySQL]]></category>
		<category><![CDATA[php crud]]></category>
		<category><![CDATA[PHP CRUD using Bootstrap 5]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=16702</guid>

					<description><![CDATA[<p>To perform CRUD (Create, Read, Update, Delete) operations using PHP, Bootstrap 5, and MySQL, you will need to follow the steps below: Create a database in MySQL <a class="read-more-link" href="https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/">CRUD operation using PHP Bootstrap 5 &amp; MySQL</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>To perform CRUD (Create, Read, Update, Delete) operations using PHP, Bootstrap 5, and MySQL, you will need to follow the steps below:</p>



<p>Create a database in MySQL and create a table in it.</p>



<ol class="wp-block-list"></ol>



<p>For example, let&#8217;s create a database named &#8220;blog&#8221; and a table named &#8220;students&#8221; with the following fields:</p>



<ul class="wp-block-list">
<li>id (primary key, auto-increment)</li>



<li>name</li>



<li>email</li>



<li>phone</li>



<li>course</li>
</ul>



<p>Create your database and create the table as shown below to get start with CRUD app using php mysql.</p>



<pre class="wp-block-code"><code>CREATE TABLE students (
    id INT(255) AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    phone VARCHAR(255) NOT NULL,
    course VARCHAR(255) NOT NULL
)</code></pre>



<p><strong>Step 1:</strong> Create a file named <strong>student-create.php</strong> and paste the form code to save the data:</p>



<pre class="wp-block-code"><code>&lt;?php
session_start();
?>

&lt;!doctype html>
&lt;html lang="en">

&lt;head>
    &lt;!-- Required meta tags -->
    &lt;meta charset="utf-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1">

    &lt;!-- Bootstrap CSS -->
    &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

    &lt;title>Student Create&lt;/title>
&lt;/head>

&lt;body>

    &lt;div class="container mt-5">

        &lt;?php include('message.php'); ?>

        &lt;div class="row">
            &lt;div class="col-md-12">
                &lt;div class="card">
                    &lt;div class="card-header">
                        &lt;h4>Student Add
                            &lt;a href="index.php" class="btn btn-danger float-end">BACK&lt;/a>
                        &lt;/h4>
                    &lt;/div>
                    &lt;div class="card-body">
                        &lt;form action="code.php" method="POST">

                            &lt;div class="mb-3">
                                &lt;label>Student Name&lt;/label>
                                &lt;input type="text" name="name" class="form-control">
                            &lt;/div>
                            &lt;div class="mb-3">
                                &lt;label>Student Email&lt;/label>
                                &lt;input type="email" name="email" class="form-control">
                            &lt;/div>
                            &lt;div class="mb-3">
                                &lt;label>Student Phone&lt;/label>
                                &lt;input type="text" name="phone" class="form-control">
                            &lt;/div>
                            &lt;div class="mb-3">
                                &lt;label>Student Course&lt;/label>
                                &lt;input type="text" name="course" class="form-control">
                            &lt;/div>
                            &lt;div class="mb-3">
                                &lt;button type="submit" name="save_student" class="btn btn-primary">Save Student&lt;/button>
                            &lt;/div>

                        &lt;/form>
                    &lt;/div>
                &lt;/div>
            &lt;/div>
        &lt;/div>
    &lt;/div>

    &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js">&lt;/script>
&lt;/body>

&lt;/html></code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/01-1024x452.jpg" alt="" class="wp-image-16703" width="840" height="370" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/01-1024x452.jpg 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/01-300x133.jpg 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/01-768x339.jpg 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/01.jpg 1227w" sizes="(max-width: 840px) 100vw, 840px" /></figure>



<p><strong>Step 2: </strong>Create a file <strong>dbcon.php</strong> for the  Database Connection in PHP MySQL.</p>



<pre class="wp-block-code"><code>&lt;?php

$con = mysqli_connect("localhost","root","","blog");

if(!$con){
    die('Connection Failed'. mysqli_connect_error());
}

?></code></pre>



<p><strong>Step 3:</strong> Create a file named <strong>message.php</strong> file and this file will be used to display the message in every file where ever is required.</p>



<pre class="wp-block-code"><code>&lt;?php
    if(isset($_SESSION&#91;'message'])) :
?>

    &lt;div class="alert alert-warning alert-dismissible fade show" role="alert">
        &lt;strong>Hey!&lt;/strong> &lt;?= $_SESSION&#91;'message']; ?>
        &lt;button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">&lt;/button>
    &lt;/div>

&lt;?php 
    unset($_SESSION&#91;'message']);
    endif;
?></code></pre>



<p><strong>Step 4:</strong> Create a file named <strong>index.php</strong> and fetch data from database as given below code:</p>



<pre class="wp-block-code"><code>&lt;?php
    session_start();
    require 'dbcon.php';
?>
&lt;!doctype html>
&lt;html lang="en">

&lt;head>
    &lt;!-- Required meta tags -->
    &lt;meta charset="utf-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1">

    &lt;!-- Bootstrap CSS -->
    &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

    &lt;title>Student CRUD&lt;/title>
&lt;/head>

&lt;body>

    &lt;div class="container mt-4">

        &lt;?php include('message.php'); ?>

        &lt;div class="row">
            &lt;div class="col-md-12">
                &lt;div class="card">
                    &lt;div class="card-header">
                        &lt;h4>Student Details
                            &lt;a href="create-student.php" class="btn btn-primary float-end">Add Students&lt;/a>
                        &lt;/h4>
                    &lt;/div>
                    &lt;div class="card-body">

                        &lt;table class="table table-bordered table-striped">
                            &lt;thead>
                                &lt;tr>
                                    &lt;th>ID&lt;/th>
                                    &lt;th>Student Name&lt;/th>
                                    &lt;th>Email&lt;/th>
                                    &lt;th>Phone&lt;/th>
                                    &lt;th>Course&lt;/th>
                                    &lt;th>Action&lt;/th>
                                &lt;/tr>
                            &lt;/thead>
                            &lt;tbody>
                                &lt;?php 
                                    $query = "SELECT * FROM students";
                                    $query_run = mysqli_query($con, $query);

                                    if(mysqli_num_rows($query_run) > 0)
                                    {
                                        foreach($query_run as $student)
                                        {
                                            ?>
                                &lt;tr>
                                    &lt;td>
                                        &lt;?= $student&#91;'id']; ?>
                                    &lt;/td>
                                    &lt;td>
                                        &lt;?= $student&#91;'name']; ?>
                                    &lt;/td>
                                    &lt;td>
                                        &lt;?= $student&#91;'email']; ?>
                                    &lt;/td>
                                    &lt;td>
                                        &lt;?= $student&#91;'phone']; ?>
                                    &lt;/td>
                                    &lt;td>
                                        &lt;?= $student&#91;'course']; ?>
                                    &lt;/td>
                                    &lt;td>
                                        &lt;a href="student-view.php?id=&lt;?= $student&#91;'id']; ?>"
                                            class="btn btn-info btn-sm">View&lt;/a>
                                        &lt;a href="student-edit.php?id=&lt;?= $student&#91;'id']; ?>"
                                            class="btn btn-success btn-sm">Edit&lt;/a>
                                        &lt;form action="code.php" method="POST" class="d-inline">
                                            &lt;button type="submit" name="delete_student" value="&lt;?=$student&#91;'id'];?>"
                                                class="btn btn-danger btn-sm">Delete&lt;/button>
                                        &lt;/form>
                                    &lt;/td>
                                &lt;/tr>
                                &lt;?php
                                        }
                                    }
                                    else
                                    {
                                        echo "&lt;h5> No Record Found &lt;/h5>";
                                    }
                                ?>

                            &lt;/tbody>
                        &lt;/table>

                    &lt;/div>
                &lt;/div>
            &lt;/div>
        &lt;/div>
    &lt;/div>

    &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js">&lt;/script>

&lt;/body>

&lt;/html></code></pre>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/03-1024x294.jpg" alt="" class="wp-image-16705" width="840" height="241" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/03-1024x294.jpg 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/03-300x86.jpg 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/03-768x220.jpg 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/03.jpg 1220w" sizes="(max-width: 840px) 100vw, 840px" /></figure>



<p><strong>Step 5:</strong> Create a file named <strong>sudent-edit.php</strong> for edit and update data in php: </p>



<pre class="wp-block-code"><code>&lt;?php
session_start();
require 'dbcon.php';
?>

&lt;!doctype html>
&lt;html lang="en">
  &lt;head>
    &lt;!-- Required meta tags -->
    &lt;meta charset="utf-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1">

    &lt;!-- Bootstrap CSS -->
    &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

    &lt;title>Student Edit&lt;/title>
&lt;/head>
&lt;body>
  
    &lt;div class="container mt-5">

        &lt;?php include('message.php'); ?>

        &lt;div class="row">
            &lt;div class="col-md-12">
                &lt;div class="card">
                    &lt;div class="card-header">
                        &lt;h4>Student Edit 
                            &lt;a href="index.php" class="btn btn-danger float-end">BACK&lt;/a>
                        &lt;/h4>
                    &lt;/div>
                    &lt;div class="card-body">

                        &lt;?php
                        if(isset($_GET&#91;'id']))
                        {
                            $student_id = mysqli_real_escape_string($con, $_GET&#91;'id']);
                            $query = "SELECT * FROM students WHERE id='$student_id' ";
                            $query_run = mysqli_query($con, $query);

                            if(mysqli_num_rows($query_run) > 0)
                            {
                                $student = mysqli_fetch_array($query_run);
                                ?>
                                &lt;form action="code.php" method="POST">
                                    &lt;input type="hidden" name="student_id" value="&lt;?= $student&#91;'id']; ?>">

                                    &lt;div class="mb-3">
                                        &lt;label>Student Name&lt;/label>
                                        &lt;input type="text" name="name" value="&lt;?=$student&#91;'name'];?>" class="form-control">
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Email&lt;/label>
                                        &lt;input type="email" name="email" value="&lt;?=$student&#91;'email'];?>" class="form-control">
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Phone&lt;/label>
                                        &lt;input type="text" name="phone" value="&lt;?=$student&#91;'phone'];?>" class="form-control">
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Course&lt;/label>
                                        &lt;input type="text" name="course" value="&lt;?=$student&#91;'course'];?>" class="form-control">
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;button type="submit" name="update_student" class="btn btn-primary">
                                            Update Student
                                        &lt;/button>
                                    &lt;/div>

                                &lt;/form>
                                &lt;?php
                            }
                            else
                            {
                                echo "&lt;h4>No Such Id Found&lt;/h4>";
                            }
                        }
                        ?>
                    &lt;/div>
                &lt;/div>
            &lt;/div>
        &lt;/div>
    &lt;/div>

    &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js">&lt;/script>
&lt;/body>
&lt;/html></code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="196" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/04-1024x196.jpg" alt="" class="wp-image-16706" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/04-1024x196.jpg 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/04-300x57.jpg 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/04-768x147.jpg 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/04.jpg 1232w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p><strong>Step 6:</strong> Create a file named <strong>student-view.php</strong> and display data by specific id.</p>



<pre class="wp-block-code"><code>&lt;?php
require 'dbcon.php';
?>
&lt;!doctype html>
&lt;html lang="en">
  &lt;head>
    &lt;!-- Required meta tags -->
    &lt;meta charset="utf-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1">

    &lt;!-- Bootstrap CSS -->
    &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

    &lt;title>Student View&lt;/title>
&lt;/head>
&lt;body>

    &lt;div class="container mt-5">

        &lt;div class="row">
            &lt;div class="col-md-12">
                &lt;div class="card">
                    &lt;div class="card-header">
                        &lt;h4>Student View Details 
                            &lt;a href="index.php" class="btn btn-danger float-end">BACK&lt;/a>
                        &lt;/h4>
                    &lt;/div>
                    &lt;div class="card-body">

                        &lt;?php
                        if(isset($_GET&#91;'id']))
                        {
                            $student_id = mysqli_real_escape_string($con, $_GET&#91;'id']);
                            $query = "SELECT * FROM students WHERE id='$student_id' ";
                            $query_run = mysqli_query($con, $query);

                            if(mysqli_num_rows($query_run) > 0)
                            {
                                $student = mysqli_fetch_array($query_run);
                                ?>
                                
                                    &lt;div class="mb-3">
                                        &lt;label>Student Name&lt;/label>
                                        &lt;p class="form-control">
                                            &lt;?=$student&#91;'name'];?>
                                        &lt;/p>
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Email&lt;/label>
                                        &lt;p class="form-control">
                                            &lt;?=$student&#91;'email'];?>
                                        &lt;/p>
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Phone&lt;/label>
                                        &lt;p class="form-control">
                                            &lt;?=$student&#91;'phone'];?>
                                        &lt;/p>
                                    &lt;/div>
                                    &lt;div class="mb-3">
                                        &lt;label>Student Course&lt;/label>
                                        &lt;p class="form-control">
                                            &lt;?=$student&#91;'course'];?>
                                        &lt;/p>
                                    &lt;/div>

                                &lt;?php
                            }
                            else
                            {
                                echo "&lt;h4>No Such Id Found&lt;/h4>";
                            }
                        }
                        ?>
                    &lt;/div>
                &lt;/div>
            &lt;/div>
        &lt;/div>
    &lt;/div>
    
    &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js">&lt;/script>
&lt;/body>
&lt;/html></code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/5-1024x145.jpg" alt="" class="wp-image-16707" width="840" height="118" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/05/5-1024x145.jpg 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/5-300x43.jpg 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/5-768x109.jpg 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/05/5.jpg 1162w" sizes="auto, (max-width: 840px) 100vw, 840px" /></figure>



<p><strong>Step 7: </strong>Create a file named <strong>code.php</strong> and paste the below code.</p>



<pre class="wp-block-code"><code>&lt;?php
session_start();
require 'dbcon.php';

if(isset($_POST&#91;'save_student']))
{
    $name = mysqli_real_escape_string($con, $_POST&#91;'name']);
    $email = mysqli_real_escape_string($con, $_POST&#91;'email']);
    $phone = mysqli_real_escape_string($con, $_POST&#91;'phone']);
    $course = mysqli_real_escape_string($con, $_POST&#91;'course']);

    $query = "INSERT INTO students (name,email,phone,course) VALUES ('$name','$email','$phone','$course')";

    $query_run = mysqli_query($con, $query);
    if($query_run)
    {
        $_SESSION&#91;'message'] = "Student Created Successfully";
        header("Location: index.php");
        exit(0);
    }
    else
    {
        $_SESSION&#91;'message'] = "Student Not Created";
        header("Location: index.php");
        exit(0);
    }
}

if(isset($_POST&#91;'delete_student']))
{
    $student_id = mysqli_real_escape_string($con, $_POST&#91;'delete_student']);

    $query = "DELETE FROM students WHERE id='$student_id' ";
    $query_run = mysqli_query($con, $query);

    if($query_run)
    {
        $_SESSION&#91;'message'] = "Student Deleted Successfully";
        header("Location: index.php");
        exit(0);
    }
    else
    {
        $_SESSION&#91;'message'] = "Student Not Deleted";
        header("Location: index.php");
        exit(0);
    }
}

if(isset($_POST&#91;'update_student']))
{
    $student_id = mysqli_real_escape_string($con, $_POST&#91;'student_id']);

    $name = mysqli_real_escape_string($con, $_POST&#91;'name']);
    $email = mysqli_real_escape_string($con, $_POST&#91;'email']);
    $phone = mysqli_real_escape_string($con, $_POST&#91;'phone']);
    $course = mysqli_real_escape_string($con, $_POST&#91;'course']);

    $query = "UPDATE students SET name='$name', email='$email', phone='$phone', course='$course' WHERE id='$student_id' ";
    $query_run = mysqli_query($con, $query);

    if($query_run)
    {
        $_SESSION&#91;'message'] = "Student Updated Successfully";
        header("Location: index.php");
        exit(0);
    }
    else
    {
        $_SESSION&#91;'message'] = "Student Not Updated";
        header("Location: index.php");
        exit(0);
    }

}

?></code></pre>



<p><strong>Thanks for Visiting</strong></p>
<p>The post <a href="https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/">CRUD operation using PHP Bootstrap 5 &amp; MySQL</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/crud-operation-using-php-bootstrap-5-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
