Friday 25 May 2018

CRUD(Create,Retrieve,Update,Delete) Operation in PHP With MYSQL(Mini Project)

Step 1: Start the XAMPP server
Click on the "Start" button next to "Apache" to start your Apache Web server and also start "MySQL"

Step 2: Go to admin of  "MySQL"  button then go to  phpMyAdmin
Step 3: Create database std in phpMyAdmin.
Step 4:Create table stud in same database(std) and add fields like(firstname,lastname,address,mobileno,gender,qualification,nationality)in below figure
Step 5:



Step 6:Create  main.php  page
<html>
<Style>
a
{
            font-family:segoe script;
            color:blue;
            font-size:20;
}
a:hover
{
            color:red;
            font-size:22;
}
</style>
<body bgcolor="skyblue">
<center>
<br><br><br>
<a href="register.php"  target="iframe1">Registration page</a>&nbsp&nbsp&nbsp&nbsp
<a href="showinfo.php" target="iframe1" >show information</a>&nbsp&nbsp&nbsp&nbsp
<a href="update.php" target="iframe1">update information</a>&nbsp&nbsp&nbsp&nbsp
<a href="delete.php" target="iframe1">delete information</a>&nbsp&nbsp&nbsp
 <br><br>
<iframe name="iframe1" id="iframe" height="500" width="900" >
</iframe>
<center>
</body>
</html>
Step 7:
a)Add register.php page
<html>
<style>
input
{
            border-color:white;
            border-radius:5px;
}
input:hover
{
             border-color:aqua;
}
</style>
<body>
<form method="post" action="connect.php" >
<center><h3>Registration Page</h3></center>
First name: <input type="text" name="fname" required><br><br>
Last name: <input type="text" name="lname" required><br><br>
Address: <input type="text" name="add" required><br><br>
Mobile NO: <input type="number" name="mno" required><br><br>
Qualification: 10th<input type="checkbox" name="demo[]" value="10th">
12th<input type="checkbox" name="demo[]" value="12th">
diploma<input type="checkbox" name="demo[]" value="diploma">
degree<input type="checkbox" name="demo[]" value="degree"><br><br>
Gender: male <input type="radio" name="gender" value="Male"> Female <input type="radio" name="gender" value="Female"><br><br>
Nationality: <select name="nation" required>
                                                <option ></option>
                                                <option value="INDIAN">INDIAN</option>
                                                <option value="OTHER">OTHER</option>
                                                </select><br><br>
<input type="submit" name="submit" value="SUBMIT">
</form>
</body>
</html>
b)add connect.php page
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="std";
$con=mysqli_connect($servername,$username,$password,$dbname);
if(!$con)
{
            die("<br>could not connect".mysqli_error());
}else
{
             echo "<br>Server Connected sucessfully";
}

if(isset($_POST["submit"]))
{
            $fn=$_POST["fname"];
            $ln=$_POST["lname"];
            $ad=$_POST["add"];
            $mo=$_POST["mno"];
            $gen=$_POST["gender"];      
            $nat=$_POST["nation"];
            $ch1=$_POST["demo"];
            $ch2="";
            foreach($ch1 as $ch3)
            {
                                    $ch2.=$ch3.",";
            }
            $sql="INSERT INTO stud VALUES('$fn','$ln','$ad',$mo,'$gen','$ch2','$nat')";

if(mysqli_query($con,$sql))
{
            echo"<br>Data added Successfully";
}
else
{
            echo "<br>Error Adding data";
}
           
}
?>
Step 8:
a) Add showinfo.php page
<html>
<style>
input
{
            border-color:white;
            border-radius:5px;
}
input:hover
{
             border-color:aqua;
}
</style>
<body>
<form method="post">
<h3><center>Get Information Here<center></h3>
Enter Your First name :<input type="text" name="fname"><br><br>
Enter your Mobile No:<input type="number" name="mon"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
include "server.php";
if(isset($_POST["submit"]))
{
            $fn=$_POST["fname"];
            $mn=$_POST["mon"];
            $sql="SELECT * FROM stud WHERE mobileno=$mn";
            $res=mysqli_query($con,$sql);
            if(mysqli_num_rows($res)>0)
            {
            echo"<br>Information is";
            while($row=mysqli_fetch_assoc($res))
            {
                        echo "<br><br>First name:{$row["firstname"]}";
                        echo "<br><br>Last name:{$row["lastname"]}";
                        echo "<br><br>Address:{$row["address"]}";
                        echo "<br><br>Mobile No:{$row["mobileno"]}";
                        echo "<br><br>Gender:{$row["gender"]}";
                        echo "<br><br>Qualifiaction:{$row["qualification"]}";
                        echo "<br><br>Nationality:{$row["nationlity"]}";
            }
            }
           
}
?>
b)add server.php page
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="std";
$con=mysqli_connect($servername,$username,$password,$dbname);
if(!$con)
{
            die("<br>could not connect to server ".mysqli_error());
}else
{
             echo "<br>Server Connected sucessfully";
}
?>
Step 9:
a)Add update.php page
<html>
<style>
input
{
            border-color:white;
            border-radius:5px;
}

input:hover
{
             border-color:aqua;
}
</style>
<body>
<form method="post" action="up.php" >
Previous mobileno:<input type="number" name="pname"><br><br>
<center><h3>Update information</h3></center>
First name: <input type="text" name="fname" ><br><br>
Last name: <input type="text" name="lname" ><br><br>
Address: <input type="text" name="add" ><br><br>
Mobile NO: <input type="number" name="mno" ><br><br>
Qualification: 10th<input type="checkbox" name="demo[]" value="10th">
12th<input type="checkbox" name="demo[]" value="12th">
diploma<input type="checkbox" name="demo[]" value="diploma">
degree<input type="checkbox" name="demo[]" value="degree"><br><br>
Gender: male <input type="radio" name="gender" value="Male"> Female <input type="radio" name="gender" value="Female"><br><br>
Nationality: <select name="nation" >
                                                <option ></option>
                                                <option value="INDIAN">INDIAN</option>
                                                <option value="OTHER">OTHER</option>
                                                </select><br><br>
<input type="submit" name="submit" value="SUBMIT">
</form>
</body>
</html>
b) add up.php page
<?php
include "server.php";
if(isset($_POST["submit"]))
{
            $pn=$_POST["pname"];
            $fn=$_POST["fname"];
            $ln=$_POST["lname"];
            $ad=$_POST["add"];
            $mo=$_POST["mno"];
            $gen=$_POST["gender"];      
            $nat=$_POST["nation"];
            $ch1=$_POST["demo"];
            $ch2="";
            foreach($ch1 as $ch3)
            {
                                    $ch2.=$ch3.",";
            }
            $sql="update stud set firstname='$fn',lastname='$ln',address='$ad',mobileno='$mo',gender='$gen',qualification='$ch2',nationlity='$nat' WHERE mobileno=$pn";

if(mysqli_query($con,$sql))
{
            echo"<br>Data Updated Successfully";
}
}
?>
Step 10:
a)Add delete.php page
<html>
<style>
input
{
            border-color:white;
            border-radius:5px;
}
input:hover
{
             border-color:aqua;
}
</style>
<body>
<form method="post" action="delete1.php" >
Enter Your mobileno:<input type="number" name="pno"><br><br>
<input type="submit" name="submit" value="DELETE">
</form>
</body>
</html>
b)add delete1.php
 <?php
include "server.php";
if(isset($_POST["submit"]))
{
            $pn=$_POST["pno"];
            $sql="delete from stud where mobileno= $pn";
            if(mysqli_query($con,$sql))
            {
                        echo "<br>Data deleted succesfully";
            }
            else
            {
                        echo "<br>error";
            }
}
?>
Step 11:
run your application


1 comment:

  1. Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.

    ReplyDelete

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...