PHP – MySQL – Update Records

Syntax:

UPDATE table_name
SET column1=value, column2=value2,…
WHERE some_column=some_value

<?php
// Create connection
// Statement: mysqli_connect(host,username,password,dbname)
// NOTICE: se lo script è installato nello stesso server del Data Base, host->localhost
$con=mysqli_connect("localhost","lucedigi_user","mypassword","lucedigi_testphp");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Update records START
// Set the Age of Peter Griffin to 36
mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");
// Update records END

mysqli_close($con); 
echo "Great! Connection Closed!"; 
?>

phpMyAdmin

BEFORE:

mysql-0004

AFTER:

mysql-0006