In this lesson our instructor talks about SQL command: UPDATE. He discusses UPDATE statement, using UPDATE from PHP, htmlspecialchars(), and addslashes(). He ends the lesson with nine helpful homework challenges.
An UPDATE statement is an SQL command used to update the data values of specified rows in database
tables. It has the syntax:
UPDATE items SET name=‘Blue T-Shirt’, price=8.99 WHERE itemID=1001;
Its WHERE clause operates just like for SELECT statements to be able to select
specific rows from a table. It can thus also use comparison & logical operations in its where condition.
To update column values for all rows in a table, the WHERE clause is simply omitted:
UPDATE items SET imageFileExt=‘jpg’;
Running an UPDATE query from PHP works the same way as running an INSERT query from
PHP because it does not return a result set. To process an UPDATE query's results:
The result of the query() method can be tested for its truth value to test the success of the
The MySQLi->affected_rows property can also be accessed to get the number of rows that were
htmlspecialchars() is a built-in PHP function that will encode any HTML special characters within a
string as proper HTML entities. The function will encode the following special characters by default:
“ – becomes "
< - becomes <
> - becomes >
& – becomes &
addslashes() is a built-in PHP function that is used to escape characters that should be escaped in
database queries. It will escape the following characters:
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.