Up-Date data in SQL database using Php

In last two posts i discus how to create connection and how to insert data in data base using php.

Insert-data-in-SQL-database-using-PHP


Create-connection-with-sql-database-in-php

In this post i will show you how to update data in SQL database table using php.
so for this first we need database connection which we create in first post so just include that file and then code for update query


Let suppose we have to update user name so we select that user from login table and set a new value of it where the perous value is equal to the value we gave to it.


<?php
include "conn.php";

$new_user = $_POST['usr1'];
$user = $_POST['usr2'];

$sql = "update login 
set user='".$new_user."' 
where user='".$user."';";

if ($conn->query($sql) === TRUE) {
    echo "Record Up-date successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

No comments

Powered by Blogger.