PHP MySQL Update Record
From w3cyberlearnings
Contents |
PHP MySQL Update Record
Update record use the UPDATE statement. You need to know what and where you want to update a record.
Syntax
$update_query = 'UPDATE student SET first_name="lili", last_name="lee" WHERE student_id=3'; mysql_query($update_query, $connection);
Example 1
<?php define('HOST', 'localhost'); define('USER', 'root'); define('PASS', 'yeething'); define('DBNAME', 'woowood'); $connection = mysql_connect(HOST, USER, PASS); if (!$connection) { die("can not connect to the server!<br/>"); } else { $rdb = mysql_select_db(DBNAME); if (!$rdb) { die("The " . DBNAME . "database could not be selected"); } else { $update_query = 'UPDATE student SET first_name="lili", last_name="lee" WHERE student_id=3'; if (!mysql_query($update_query, $connection)) { echo "Can't update student table: " . mysql_error($connection); } else { echo "You have successfully update the student table."; } } } mysql_close($connection); ?>
Output
You have successfully update the student table.