Skip to main content

Crud Operation In PHP

 What is crud Operation in php?

Or

Write a program where php program connect MySQLi database?

Today we know about crud Operation and how to connect MySQLi database with php program.

CRUD OPERATION 

  •     Crud Operation stands for create,  read (select), update and delete.First of all we create a MySQLi database in phpmyadmin. so we have 'mydb' database and table name 'student'.now create a connection of database php file connection.php and write this code given below:-

Example :   'connection.php',

<?php
$hostname="localhost";
$username="root";
$password="";
$dbname="mydb";
$con=mysqli_connect($hostname,
$username,$password,$dbname);
if($con){
    echo"connected";
}
else{
echo"not connected";
}
?>
<?php

create database with php:

 create database with php command ,code given below:-

Example:

 
$sql = 'CREATE Database mydb';
   
   

  •  now we insert data  in database table('student').code given below:   

Example:  'insert.php'

if(isset($_POST['login'])){
    $gmail=$_POST['gmail'];
    $password=$_POST['password'];

$query="insert into `student`(`gmail`
;`password`)
values('$gmail','$password')";
   
$result=mysqli_query($con,$query);
    if($result){
        echo"inserted";
    }
    else{
      echo"not inserted";
}
  
  •       now we perform read(select) crud operation.here we fetch data from our database so this code given below:-

Example: 'read.php'

 <?php
include ("connection.php");
include ("insert.php");
include ("update.php");
include ("delete.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>crud operation</title>
<table border="0"  bgcolor="aqua"
cellpadding="10" >
    <thead>
      DATABASE of Student
    <tr>
    <th>Gmail</th>
    <th>password</th>
    </tr>
  </thead>
  <tbody>
   <?php
   $sql="SELECT * FROM userdata";
//select data from database

   $result=mysqli_query($con,$sql);
 
   while ($row=mysqli_fetch_assoc
($result)) {

  echo "<tr>
 
    <td> ".$row['gmail']."</td>
   
    <td>".$row['password']."</td>

    </tr>";

  }
  ?>

  •        If we want update data from database record then we write this code which given below:

Example:'update.php'

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cicst";

// Create connection
$conn = new mysqli($servername,
$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed:".$conn->
connect_error);
}
//update data in record
$sq ="UPDATE MyGuests SET
lastname='Doe' WHERE id=2";

if ($conn->query($sq) === TRUE) {
echo "Record updated successfully";
} else {
echo"Error updating:".$conn->error;
}

$conn->close();
?>

  •        If we want delete data from database record then we write this code which given below:

Example:'delete.php'

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cicst";

// Create connection
$conn = new mysqli($servername,
$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed:".$conn->
connect_error);
}
//delete data from record in mysql
$sql ="DELETE FROM MyGuests
WHERE id=3";

if ($conn->query($sql) === TRUE) {
 echo "Record deleted successfully";
} else {
echo"Error deleting :".$conn->error;
}

$conn->close();


Comments

Popular posts from this blog

Introduction of php and it's features

 what is php ? what is features of php language? Introduction of PHP  PHP is a server site scripting language. which we use to create a dynamic  content, website  and web application.  PHP language is develop by Rasmus Lerdorf in 1994. In this time, PHP is a most popular scripting language. Most popular website as facebook and yahoo developed by php language. Features of PHP Php is a most popular and secondary used for world wide scripting language. there are many features of php language:- simple and easy to learn open source error reporting faster case sensitive loosely type language independent plateform Simple And easy to learn PHP is a very simple to use read and write.PHP language understandable and user-friendly. user and developer easily identify PHP code. Interpreted language PHP is an interpreted language, which means there is no need for compilation. Interpreters run through a program line by line and execute the code. PHP language no need of compiler...

How to create a table in html

  Hello dosto 🙏🙏 Aaj ham dekhenge ki kaise html Me table create karte hai . Create A Table In Html: Html me table create karne ke liye  for example ham student name ki table banayenge:- <!DOCTYPE html> <html> <head> <Title>Creating a table</title> </head> <body> <table border="1" cellspacing="0"> <tr> <tr>student table</tr> <th>name</th> <th>class</th> <th>address</th> </tr> <tr> <td>ram</td> <td>bca</td> <td>rampur</td> </tr> </tr> </table> </body> </Html> Coding karne ke baad apka Student name ki table ban Jati hai If this information is helpful, To aisi hi coding sekhna chahte to neeche comments kare Thanks 

Introduction of Android and it's features

 What is Android? Describe Android os. Write introduction of Android? Introduction of Android  Android is a mobile operating system developed by Google. It is based on a modified version of the Linux kernel and other open source software, and is designed primarily for touchscreen mobile devices such as smartphones and tablets. Android's user interface is based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input. In addition to touchscreen devices, Google has further developed Android TV for televisions, Android Auto for cars, and Wear OS for wrist watches, each with a specialized user interface. Features of Android  Android is a mobile operating system developed by Google. It is used on a wide range of devices, including smartphones, tablets, and wearable devices. Some of the features of Android include:- Customizable...