Display Code
<?php
$dbservername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="test_curd";
$con=mysqli_connect($dbservername,$dbusername,$dbpassword,$dbname);
if ($con) {
# code...
// echo "Connection is set";
// DISPLAY CODE HERE
$sql=" select * from curd_table";
$res=mysqli_query($con,$sql);//query fired
// print_r($res);//human can read this statement
if (mysqli_num_rows($res) >0)
{
# code...
$x=mysqli_fetch_assoc($res);
/*
echo $x['username'];
echo "<br/>";
echo $x['password'];
*/
print_r($x);
}
}
else{
echo "Something Went Wrong";
}
?>
Insert code
<?php
session_start();
session_destroy();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Insert php</title>
</head>
<body>
<div style="margin-left:35%; margin-top:20%; margin-right:35%;">
<form action="" method="POST">
<input type="text" name="username" placeholder="Enter your Name...." style="height:20px; width:100%; border-radius:20px; outline-color: none; outline: none;">
<br><br>
<input type="password" name="password" placeholder="Enter your password...." style="height:20px; width:100%; border-radius:20px; outline: none;outline-color: none;">
<br><br>
<div style="margin-left:35%;">
<input type="submit" name="submit" value="Insert" style="padding: 5px;">
</div>
</form>
</div>
</body>
</html>
<?php
$dbservername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="test_curd";
$con=mysqli_connect($dbservername,$dbusername,$dbpassword,$dbname);
if ($con) {
# code...
// echo "Connection Is Successfull";
if (isset($_POST['submit'])) {
# code...
$username=$_POST['username'];
$password=$_POST['password'];
$sql="Insert into curd_table(username,password) value('$username','$password')";
$res=mysqli_query($con,$sql);
if ($res) {
# code...
echo "Successfull data inserted";
}
}
}
else{
echo "something went wrong ";
}
?>
Update code
$dbservername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="test_curd";
$con=mysqli_connect($dbservername,$dbusername,$dbpassword,$dbname);
if ($con) {
# code...
// echo "Connection is succssfull ";
$sql="update curd_table set username='Kajol',password='kachhap' where id=2";//sql statement here
$res=mysqli_query($con,$sql);
if ($res) {
# code..
// print_r($res); Human can read this statement
echo "succssfully Done!";
}
}
else{
echo "Something went wrong";
}
?>
Delete Code
<?php
$dbservername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="test_curd";
$con=mysqli_connect($dbservername,$dbusername,$dbpassword,$dbname);
if ($con) {
# code...
// echo "Connection is set";
$sql="delete from curd_table where id=1";
$res=mysqli_query($con,$sql);
// print_r($res); //Human can read this sql statement
if ($res) {
# code...
echo "Successfully Done!";
}
}
else{
echo "Something Went Wrong";
}
?>
Comments