PHP MySQL update Query Syntax in the Table with MySQLi Example Code

PHP Update Data in MySQL

To change the value of previously saved recode, we have to use the update query.

In other words update query is used to update existing records.

Caution:Here you have to use the where clause and where clause is used to define which records should have to update. If you can not use where clause all the records are updated default.

Example – 1 Update Data in MySQL Example

`
 <?php
$server = "localhost";
$user = "root";
$password = "";
$dbname = "elex_tutorial";

// Create connection
$connection = mysqli_connect($server, $user, $password, $dbname);
// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "UPDATE `User` SET `age`='30' WHERE id=1";

if (mysqli_query($connection, $sql)) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . mysqli_error($connection);
}

mysqli_close($connection);
?> 

In the above code, we update the record to the “User” table of “elex_tutorial” database. If the code run successfully then the output show a Record updated successfully. So you have to check in the user table also.

You can leave a response, or trackback from your own site.

2 Responses to “PHP MySQL update Query Syntax in the Table with MySQLi Example Code”

  1. Fantastic goods from you, man. I’ve understand your stuff prior to and you are just too great. I actually like what you have acquired here, certainly like what you are saying and the best way in which you are saying it. You make it entertaining and you still take care of to keep it sensible. I can’t wait to read far more from you. This is actually a terrific web site.|

  2. My spouse and I stumbled over here different web address and thought I should check things out. I like what I see so i am just following you. Look forward to going over your web page for a second time.

Leave a Reply to the article


Learn PHP

Learning & Certifications
Follow Us
Facebook Icon   Linked In Icon   Twitter Icon  
Validation and Recognition

Valid CSS! Valid HTML5!