Você está na página 1de 14

PHP Day 07

http://www.php.net
http://www.mysql.com

Geshan Manandhar
Developer,
Young Innovations Private Limited
www.geshanmanandhar.com
GeshanManandhar.com 1
List Users with actions (detail,
edit, delete)

GeshanManandhar.com 2
How to code the actions
column
► Insidewhile ($row=
mysql_fetch_array($user_records) loop
 $user_id = $row['user_id'];
$user_table .= "<td>"; //line no. 56 – day07\show_users_with_actions.php
$user_table .= "<a href=\"user_detail.php?id=$user_id\">Detail</a> - ";
$user_table .= "<a href=\"user_edit.php?id=$user_id\">Edit</a> - ";
$user_table .= "<a href=\"user_delete.php?id=$user_id\"";
$user_table .= ' onclick="javascript:return confirm(\'Do you really want to
delete?\');"';
$user_table .= ">Delete</a> - ";
$user_table .= "</td>\n";

GeshanManandhar.com 3
User Detail

GeshanManandhar.com 4
Show user table construction
code

GeshanManandhar.com 5
Output of user_detail.php?
id=X

GeshanManandhar.com 6
Update User.
► Form is a combination of
prog46_user_reg.php and user_detail.php.
► user_edit.php is a form with values of the
user_id passed via the URL.
► Check out the code at day07\user_edit.php
► 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

GeshanManandhar.com 7
Output of User Update form

GeshanManandhar.com 8
Edit user the function

GeshanManandhar.com 9
Delete User
► In every delete call always confirm the
delete operation, preferably with
javascript.
► Similar to user_detail but this operation
deletes the record from the database.
► Usage of parameter via URL and fetched
in $_GET variable.
► Full code at: day07\user_delete.php

GeshanManandhar.com 10
Delete user function code

GeshanManandhar.com 11
CRUD done
► That sums up the regular Create Read
Update Delete (CRUD) operations.
► The common and most used operation
in any database focused application.
► Other things like search, sorting etc
are enhanced form or Read/Retrieve.
► Things to do: some sorting and join
queries for tables.
GeshanManandhar.com 12
Questions

GeshanManandhar.com 13
Assignment
► 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).
► Let there be option for type of user “Admin”,
“Super User” or “Normal User”.
► Perform CRUD operations on your login
system.

GeshanManandhar.com 14

Você também pode gostar