HOW TO UPDATE DATA IN THE DATABASE USING PHP AND MYSQLI

Hey guys, Today we are learning PHP WITH MYQLI UPDATE QUERY execute in the database. Then lets start (How to update in data in a database using PHP with MySQL).

1. HTML Source Code(Index.php)

<?php
$conn=mysqli_connect("localhost", "root", "", "testproject");
$fetchQry=mysqli_query($conn, "SELECT * FROM userdetails WHERE id=1");
$rows=mysqli_fetch_array($fetchQry);
?>

<form action="send.php" method="post">
<input type="hidden" name="id" value="<?php echo $rows['id']; ?>">
<input type="text" name="name" value="<?php echo $rows['name']; ?>">
<input type="submit" name="submit" value="Submit">
</form>

2. PHP Source Code(send.php)

<?php
$conn=mysqli_connect("localhost", "root", "", "testproject");
$name=$_POST["name"];
$id=$_POST["id"];
$query=mysqli_query($conn, "UPDATE userdetails SET name='$name' WHERE id='$id'");
if(query==true){
echo"Successfully Inserted";
}
else{
echo"Inserted Failed";
}
?>