How To Update Existing Rows in a Table

Q

How To Update Existing Rows in a Table? - MySQL FAQs - Managing Tables and Running Queries with PHP Scripts

✍: FYIcenter.com

A

Updating existing rows in a table requires to run the UPDATE statement with a WHERE clause to identify the row. The following sample script updates one row with two new values:

<?php
  include "mysql_connection.php";

  $sql = "UPDATE fyi_links SET notes='Nice site.', counts=8"
    . " WHERE id = 102";
  if (mysql_query($sql, $con)) {
    print(mysql_affected_rows() . " rows updated.\n");
  } else {
    print("SQL statement failed.\n");
  }

  mysql_close($con); 
?>

If you run this script, you will get something like this:

1 rows updated.

2007-05-11, 4788👍, 0💬