0% found this document useful (0 votes)
15 views5 pages

Hii

The document contains PHP code for performing CRUD operations on a database table including functions for insertion, display, update, and deletion of records.

Uploaded by

jayp32983
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Hii

The document contains PHP code for performing CRUD operations on a database table including functions for insertion, display, update, and deletion of records.

Uploaded by

jayp32983
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

user

<?php
$con= new mysqli('localhost','root','','crudop');
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];

//insert query
$sql = "INSERT INTO leo( name, email, mobile, password )
VALUES( '$name', '$email','$mobile', '$password' )";

//execute query
$result=mysqli_query($con,$sql);

// we will check
if($result) {
echo "data inserted successfully";
header('Location:display.php');
}else{
die(mysqli_error($con));
}
}
?>

display

<?php
$sql="Select * from leo";
$result=mysqli_query($con,$sql);
if ($result){
//step 1
// $row=mysqli_fetch_array($result);
// echo $row['name'];

while ($row=mysqli_fetch_array($result))
{
$id=$row['id'];
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];

echo'<tr>
<th scope="row">'.$id.'</th>
<td>'.$name.'</td>
<td>'.$email.'</td>
<td>'.$mobile.'</td>
<td>'.$password.'</td>
<td>

<button type="button" class="btn btn-success my-5"><a href="update.php?


updateid='.$id.'">update</a></button>
<button type="button" class="btn btn-danger my-5"><a href="delete.php?
deleteid='.$id.'">delete</a></button>
</td>
</tr>
<tr>';
}
}
?>

update

<?php
$con= new mysqli('localhost','root','','crudop');
$id = $_GET['updateid'];
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];

$sql="update leo set name='$name', email='$email', mobile='$mobile',


password='$password' where id=$id";

$result=mysqli_query($con,$sql);

if($result) {
echo "updated successfully ";
header('Location:display.php');
}else{
die(mysqli_error($con));
}
}

$sql="Select * from leo";


$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result);
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];

?>

delete

<?php
$con= new mysqli('localhost','root','','crudop');
if(isset($_GET['deleteid'])){
$id=$_GET['deleteid'];

//insert query
$sql = "delete from leo where id=$id";
//execute query
$result=mysqli_query($con,$sql);

// we will check
if($result) {
echo "deleted successfully";
header('Location:display.php');
}else{
die(mysqli_error($con));
}
}
?>

insert asp

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


• Dim con As New SqlConnection
• Dim cmd As New SqlCommand
• con.ConnectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Emp;Integrated
Security=True"
• con.Open()
• cmd = New SqlCommand("INSERT INTO employee values('" & TextBox1.Text & "', '" &
TextBox2.Text & "','" &
TextBox3.Text & "', '" & TextBox4.Text & "','" & TextBox5.Text & "', '" &
TextBox6.Text & "')", con)
• cmd.ExecuteNonQuery()
• con.Close()
• MsgBox( "data inserted successfully" )
• End Sub
• End Clas

search asp

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


• Dim con As New SqlConnection
• Dim cmd As New SqlCommand
• Dim dr As SqlDataReader
• con.ConnectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Emp;Integrated Security=True"
• con.Open()
• cmd = New SqlCommand("select * from employee1 where id= '" + searchtextbox.Text +
"'", con )
• dr = cmd.ExecuteReader
• If dr.Read Then
• emp_id.Text = dr.GetValue(0)
• TextBox2.Text = dr.GetValue(1) • TextBox3.Text = dr.GetValue(2)
• TextBox4.Text = dr.GetValue(3)
• TextBox5.Text = dr.GetValue(4)
• TextBox6.Text = dr.GetValue(5)
• TextBox7.Text = dr.GetValue(6)
• TextBox8.Text = dr.GetValue(7)
• Else
• MsgBox( "record not found!!!!" )
• End If
• con.Close()
• End Sub
• End Clas

delete asp

Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
• Dim con As New SqlConnection
• Dim cmd As New SqlCommand
• con.ConnectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Emp;Integrated Security=True"
• cmd.Connection = con
• con.Open()
• cmd.CommandText = "delete from employee1 where id= '" &
searchtextbox.Text & "‘"
• cmd.ExecuteNonQuery()
• MsgBox("record deletd successfuly")
• emp_id.Text = ""
• TextBox2.Text = "" • TextBox3.Text = ""
• TextBox4.Text = ""
• TextBox5.Text = ""
• TextBox6.Text = "" • TextBox7.Text = ""
• TextBox8.Text = ""
• End Sub
• End Class

update asp

Protected Sub Button3_Click(sender As Object, e As EventArgs)


Handles Button3.Click
• Dim con As New SqlConnection
• Dim cmd As New SqlCommand
• con.ConnectionString = "Data
Source=(localdb)\MSSQLLocalDB;Initial Catalog=Emp;Integrated
Security=True"
• cmd.Connection = con
• con.Open()
• cmd.CommandText = "update employee1 set firstname='" &
TextBox2.Text & "', Lastname='" & TextBox3.Text & "',mobilenumber
='" & TextBox4.Text & "', age ='" & TextBox5.Text & "', fathername='" &
TextBox6.Text & "',email='" & TextBox7.Text & "', gender='" &
TextBox8.Text & "' where Id='" & searchtextbox.Text & "' "
• cmd.ExecuteNonQuery()
• MsgBox("Record Updated successfully")
• emp_id.Text = ""
• TextBox2.Text = ""
• TextBox3.Text = ""
• TextBox4.Text = ""
• TextBox5.Text = ""
• TextBox6.Text = ""
• TextBox7.Text = ""
• TextBox8.Text = ""
• End Sub

You might also like