PHP/MySQL Database/Database Update
Get affected rows for an update
<?php
mysql_connect("mysql153.secureserver.net","wbex","password");
mysql_select_db("wbex");
$query = "UPDATE Employee SET salary = "39.99" ";
$result = mysql_query($query);
echo "There were ".mysql_affected_rows()." product(s) affected. ";
?>
Update data record and get the affected rows
<html>
<body>
<?php
$host="mysql153.secureserver.net";
$uname="wbex";
$pass="password";
$database="wbex";
$tablename="Employee";
$connection= mysql_connect($host,$uname,$pass) or die("Database connection failed!<br>");
$result=mysql_select_db($database) or die("Database could not be selected");
$query = "UPDATE Employee SET Firstname=\"new Name\" where id=2";
$result = mysql_query($query);
if (!$result) {
die(" Query could not be executed.<br>");
} else {
echo "<table> ";
echo " <tr>";
echo " <td colspan=\"2\">";
echo " <center><b>".mysql_affected_rows()." record updated successfully</b></center>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td>";
echo " <div align=\"right\"> Name</div>";
echo " </td>";
echo " <td>".$name. "</td>";
echo " </tr>";
echo " <tr>";
echo " <td>";
echo " <div align=\"right\">E-mail</div>";
echo " </td>";
echo " <td>".$email. "</td>";
echo " </tr>";
echo " <tr>";
echo " <td>";
echo " <div align=\"right\"> CustomerID</div>";
echo " </td>";
echo " <td>".$customerid. "</td>";
echo " </tr>";
echo "</table>";
}
?>
</body>
</html>
Update Employee table
<?php
mysql_connect("mysql153.secureserver.net","wbex","password");
mysql_select_db("wbex");
$rowID = "0001";
$name = "Kate";
$price = "12";
$query = "UPDATE Employee SET name="$name", price="$price" WHERE ID="$rowID"";
$result = mysql_query($query);
if ($result)
echo "<p>The developer has been successfully updated.</p>";
else
echo "<p>There was a problem updating the developer.</p>";
?>