PHP MYSQL : Update Records

Example code on how to update records using PHP in MYSQL database server.

<?php

// variables
$user = "localhost";
$username = "root";
$password = "password";

// connect to database
$db = new mysqli($user,$username,$password);
$db->select_db('your_databse');
        if (mysqli_connect_errno()) {
                die( "Connection failed..." );
        }

// updaterecords
$update = "UPDATE `tbl_users` SET `firstname`='newname' WHERE (`id`='1')";
if (mysqli_query($db, $update ) === TRUE) {
          $success = true;
}   


?>

0 comments: