UPDATE statement is used to modify data in the database table.
Syntax
UPDATE table_name
SET column1=value, column2=value2,.. .
WHERE some_column=some_value
Note: Please pay attention to the WHERE clause in the UPDATE syntax. The WHERE clause specifies which records need to be updated. If you want to leave out the WHERE clause, all records will be updated!
To learn more about SQL, visit our SQL tutorial.
Use an example to illustrate
Let’s first take a look at the data in the Myguests table:
We will firstname="tom " Modify the Age
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $con=mysqli_connect("localhost","root","root","test"); // 检测连接 if (mysqli_connect_errno()) { echo "连接失败: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE Myguests SET Age=23 WHERE firstname='tom'"); mysqli_close($con); ?>
Run the program
Let's take a look at the data in the table
has been modified successfully .