Presentation is loading. Please wait.

Presentation is loading. Please wait.

Day 9. SELECT INSERT UPDATE DELETE » The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE.

Similar presentations


Presentation on theme: "Day 9. SELECT INSERT UPDATE DELETE » The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE."— Presentation transcript:

1 Day 9

2 SELECT INSERT UPDATE DELETE

3 » 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

4 » 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.

5 » Form Page <input type=text name=email value= > >

6 » Processing Page <?php if ($_REQUEST[did_update] == 1){ $email = $_REQUEST[email]; $user_id = $_REQUEST[user_id]; $query = UPDATE users SET email = $email WHERE user_id = $user_id LIMIT 1; $result = mysql_query($query); if (mysql_affected_rows($result) == 1){ echo Email updated; }else{ echo Email not updated.; } ?>

7 SELECT INSERT UPDATE DELETE

8 » Single table DELETE syntax. DELETE FROM table WHERE condition » Multiple table DELETE syntax. DELETE table1.field, table2.* FROM table1, table2 WHERE condition

9 » The limit command allows you to limit the amount of records effected to the number after the command. SELECT... FROM... WHERE... LIMIT 10

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.


Download ppt "Day 9. SELECT INSERT UPDATE DELETE » The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE."

Similar presentations


Ads by Google