07 Php Mysql Update Delete

4,596 views

Published on

PHP MYSQL update and delete.

Published in: Technology

07 Php Mysql Update Delete

  1. 1. PHP Day 07 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com http://www.php.net http://www.mysql.com
  2. 2. List Users with actions (detail, edit, delete)
  3. 3. How to code the actions column <ul><li>Inside while ($row= mysql_fetch_array($user_records) loop </li></ul><ul><ul><li>$user_id = $row['user_id']; </li></ul></ul><ul><li>$user_table .= &quot;<td>&quot;; //line no. 56 – day07show_users_with_actions.php </li></ul><ul><li>$user_table .= &quot;<a href=&quot;user_detail.php?id=$user_id&quot;>Detail</a> - &quot;; </li></ul><ul><li>$user_table .= &quot;<a href=&quot;user_edit.php?id=$user_id&quot;>Edit</a> - &quot;; </li></ul><ul><li>$user_table .= &quot;<a href=&quot;user_delete.php?id=$user_id&quot;&quot;; </li></ul><ul><li>$user_table .= ' onclick=&quot;javascript:return confirm('Do you really want to delete?');&quot;'; </li></ul><ul><li>$user_table .= &quot;>Delete</a> - &quot;; </li></ul><ul><li>$user_table .= &quot;</td> &quot;; </li></ul>
  4. 4. User Detail
  5. 5. Show user table construction code
  6. 6. Output of user_detail.php?id=X
  7. 7. Update User. <ul><li>Form is a combination of prog46_user_reg.php and user_detail.php. </li></ul><ul><li>user_edit.php is a form with values of the user_id passed via the URL. </li></ul><ul><li>Check out the code at day07user_edit.php </li></ul><ul><li>It also needs a variable called id to be passed vai the URL making the URL look something like: http://localhost/php_class/day07/user_edit.php?id=5 </li></ul>
  8. 8. Output of User Update form
  9. 9. Edit user the function
  10. 10. Delete User <ul><li>In every delete call always confirm the delete operation, preferably with javascript. </li></ul><ul><li>Similar to user_detail but this operation deletes the record from the database. </li></ul><ul><li>Usage of parameter via URL and fetched in $_GET variable. </li></ul><ul><li>Full code at: day07user_delete.php </li></ul>
  11. 11. Delete user function code
  12. 12. CRUD done <ul><li>That sums up the regular Create Read Update Delete (CRUD) operations. </li></ul><ul><li>The common and most used operation in any database focused application. </li></ul><ul><li>Other things like search, sorting etc are enhanced form or Read/Retrieve. </li></ul><ul><li>Things to do: some sorting and join queries for tables. </li></ul>
  13. 13. Questions
  14. 14. Assignment <ul><li>Create a user management system with picture upload, the database only stores the filename. (keep in mind file should not be over-written in case of same filename). </li></ul><ul><li>Let there be option for type of user “Admin”, “Super User” or “Normal User”. </li></ul><ul><li>Perform CRUD operations on your login system. </li></ul>

×