Day 9
SELECT INSERT UPDATE DELETE
» The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE. UPDATE table1, table2 SET table1.field1=val1, table2.field2=val2 WHERE condition
» Can also use the mysql_affected_rows() function to retrieve number of records updated. » With UPDATE, mysql_affected_rows() will return 0 if no changes were made to the records. This does not mean the query didnt work, only that the new value was the same as the old value.
» Form Page <input type=text name= value= > >
» Processing Page <?php if ($_REQUEST[did_update] == 1){ $ = $_REQUEST[ ]; $user_id = $_REQUEST[user_id]; $query = UPDATE users SET = $ WHERE user_id = $user_id LIMIT 1; $result = mysql_query($query); if (mysql_affected_rows($result) == 1){ echo updated; }else{ echo not updated.; } ?>
SELECT INSERT UPDATE DELETE
» Single table DELETE syntax. DELETE FROM table WHERE condition » Multiple table DELETE syntax. DELETE table1.field, table2.* FROM table1, table2 WHERE condition
» The limit command allows you to limit the amount of records effected to the number after the command. SELECT... FROM... WHERE... LIMIT 10
» Now its your turn. 1.Create a Blog using your understanding of PHP and MySQL. 2.Save the files in a Blog folder. 3.Confirm the pages works in a browser. 4.Revel in your programming glory.