Today We are going to teach how to use INSERT, DELETE, UPDATE SEARCH Function in PHP
you can Use This Code to Your Day today Projects
PHP Code
0)
{
echo'data add';
} else{
echo 'adding data failed';
}
}
}catch (Exception $ex){
echo 'Error Insert' .$ex->getmessage();
}
}
//delete button
if(isset($_POST['Delete']))
{
$data = getData();
$Delete ="DELETE FROM `details` WHERE `uid`= $data[0]";
try{
$Delete_result=mysqli_query($conn,$Delete);
if($Delete_result)
{
if (mysqli_affected_rows($conn)>0)
{
echo'data delete';
} else{
echo 'deleting data failed';
}
}
}catch (Exception $ex){
echo 'Error Delete' .$ex->getmessage();
}
}
//update button
if(isset($_POST['Update']))
{
$data = getData();
$Update ="UPDATE `details` SET `user`='$data[1]',`department`='$data[2]',`serialkey`='$data[3]',`type`='$data[4]',`comments`='$data[5]' WHERE `uid` =$data[0]";
try{
$Update_result=mysqli_query($conn,$Update);
if($Update_result)
{
if (mysqli_affected_rows($conn)>0)
{
echo'data Update';
} else{
echo 'Updating data failed';
}
}
}catch (Exception $ex){
echo 'Error Delete' .$ex->getmessage();
}
}
?>
Html Code
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<!--- css code start -->
<link href="gui.css" rel="stylesheet" type="text/css">
<!--- css code end -->
<title> itasset</title>
</head>
<body>
<div class="container">
<form action="datasave.php" method="post">
<br></br>
<input type="text" name="uid" placeholder="ID" value="<?php echo $uid;?>"> <br></br>
<input type="text" name="user" placeholder="user" value="<?php echo $user;?>" > <br></br>
<input type="text" name="department" placeholder="department" value="<?php echo $department;?>"> <br></br>
<input type="text" name="serialkey" placeholder="serialkey" value="<?php echo $serialkey;?>"> <br></br>
<input type="text" name="type" placeholder="type" value="<?php echo $type;?>"> <br></br>
<input type="text" name="comments" placeholder="comments" value="<?php echo $comments;?>"> <br></br>
<input type="submit" name="search" value="search">
<input type="submit" name="insert" value="insert">
<input type="submit" name="Update" value="Update">
<input type="submit" name="Delete" value="Delete">
</div>
</form>
<a href="showtable.php" class="button">show all deta </a>
</body>
</html>