Wednesday, 11 July 2018

Update Data In a Database using php mysqli

Update Data In a Database using php mysqli

Earlier in the tutorial we created a table named "Persons". Here is how it looks:

FirstNameLastNameAge
PeterGriffin35
GlennQuagmire33


The following example updates some data in the "Persons" table:


<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");

mysqli_close($con);
?>



After the update, the "Persons" table will look like this:

FirstNameLastNameAge
PeterGriffin36
GlennQuagmire

0 comments:

Post a Comment