MySQL – Update Records with PHP

Using PHP you can update records in your MySQL tables.

phpUpdate.php

<?php

$servername = "localhost";
$username = "bob";
$password = "123456";
$db = "classDB";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
	die("Connection failed: ". $conn->connect_error);
}

$sql = "update students set uniform='dress' where gender='girl' and age > 10";

if ($conn->query($sql) === TRUE) {
	echo "Records updated";
} else {
	echo "Error: ".$sql."<br>".$conn->error;
}

$conn->close();

?>

Be the first to comment

Leave a Reply