001.
<html>
002.
<head>
003.
<title></title>
004.
</head>
005.
<body>
006.
<?
007.
include
(
"connect.php"
);
008.
if
(
$_POST
[
"hdnCmd"
] ==
"Add"
)
009.
{
010.
$strSQL
=
"INSERT INTO member "
;
011.
$strSQL
.=
"(UserID,Name,email,age) "
;
012.
$strSQL
.=
"VALUES "
;
013.
$strSQL
.=
"('"
.
$_POST
[
"txtAddUserID"
].
"','"
.
$_POST
[
"txtAddName"
].
"' "
;
014.
$strSQL
.=
",'"
.
$_POST
[
"txtAddEmail"
].
"' "
;
015.
$strSQL
.=
",'"
.
$_POST
[
"txtAddAge"
].
"') "
;
016.
$objQuery
= mysql_query(
$strSQL
);
017.
if
(!
$objQuery
)
018.
{
019.
echo
"Error Save ["
.mysql_error().
"]"
;
020.
}
021.
022.
023.
}
024.
025.
026.
if
(
$_POST
[
"hdnCmd"
] ==
"Update"
)
027.
{
028.
$strSQL
=
"UPDATE member SET "
;
029.
$strSQL
.=
"UserID = '"
.
$_POST
[
"txtEditUserID"
].
"' "
;
030.
$strSQL
.=
",Name = '"
.
$_POST
[
"txtEditName"
].
"' "
;
031.
$strSQL
.=
",email = '"
.
$_POST
[
"txtEditEmail"
].
"' "
;
032.
$strSQL
.=
",age = '"
.
$_POST
[
"txtEditAge"
].
"' "
;
033.
$strSQL
.=
"WHERE UserID = '"
.
$_POST
[
"hdnEditUserID"
].
"' "
;
034.
$objQuery
= mysql_query(
$strSQL
);
035.
if
(!
$objQuery
)
036.
{
037.
echo
"Error Update ["
.mysql_error().
"]"
;
038.
}
039.
040.
041.
}
042.
043.
044.
if
(
$_GET
[
"Action"
] ==
"Del"
)
045.
{
046.
$strSQL
=
"DELETE FROM member "
;
047.
$strSQL
.=
"WHERE UserID = '"
.
$_GET
[
"CusID"
].
"' "
;
048.
$objQuery
= mysql_query(
$strSQL
);
049.
if
(!
$objQuery
)
050.
{
051.
echo
"Error Delete ["
.mysql_error().
"]"
;
052.
}
053.
054.
055.
}
056.
057.
$strSQL
=
"SELECT * FROM member"
;
058.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
059.
?>
060.
<form name=
"frmMain"
method=
"post"
action=
"<?=$_SERVER["
PHP_SELF
"];?>"
>
061.
<input type=
"hidden"
name=
"hdnCmd"
value=
""
>
062.
<table width=
"600"
border=
"1"
>
063.
<tr>
064.
<th width=
"91"
> <div align=
"center"
>UserID </div></th>
065.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
066.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
067.
<th width=
"97"
> <div align=
"center"
>Age </div></th>
068.
<th width=
"59"
> <div align=
"center"
>Edit </div></th>
069.
<th width=
"71"
> <div align=
"center"
>
Delete
</div></th>
070.
</tr>
071.
<?
072.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
073.
{
074.
?>
075.
076.
<?
077.
if
(
$objResult
[
"UserID"
] ==
$_GET
[
"CusID"
]
and
$_GET
[
"Action"
] ==
"Edit"
)
078.
{
079.
?>
080.
<tr>
081.
<td><div align=
"center"
>
082.
<input name=
"txtEditUserID"
type=
"text"
id=
"txtEditUserID"
value=
"<?=$objResult["
UserID
"];?>"
size=
"5"
>
083.
<input name=
"hdnEditUserID"
type=
"hidden"
id=
"hdnEditUserID"
value=
"<?=$objResult["
UserID
"];?>"
size=
"5"
>
084.
</div></td>
085.
<td><input type=
"text"
name=
"txtEditName"
size=
"20"
value=
"<?=$objResult["
Name
"];?>"
></td>
086.
<td><input type=
"text"
name=
"txtEditEmail"
size=
"20"
value=
"<?=$objResult["
email
"];?>"
></td>
087.
<td><div align=
"center"
><input name=
"txtEditAge"
type=
"text"
id=
"txtEditAge"
value=
"<?=$objResult["
age
"];?>"
size=
"2"
></div></td>
088.
<td colspan=
"2"
align=
"right"
><input name=
"btnUpdate"
type=
"button"
id=
"btnUpdate"
value=
"Update"
onClick=
"frmMain.hdnCmd.value='Update';frmMain.submit();"
>
089.
<input name=
"btnCancel"
type=
"button"
id=
"btnCancel"
value=
"Cancel"
onClick=
"window.location='<?=$_SERVER["
PHP_SELF
"];?>';"
></td>
090.
</tr>
091.
<?
092.
}
093.
else
094.
{
095.
?>
096.
<tr>
097.
<td><div align=
"center"
><?=
$objResult
[
"UserID"
];?></div></td>
098.
<td><?=
$objResult
[
"Name"
];?></td>
099.
<td><?=
$objResult
[
"email"
];?></td>
100.
<td><div align=
"center"
><?=
$objResult
[
"age"
];?></div></td>
101.
<td align=
"right"
><a href=
"<?=$_SERVER["
PHP_SELF
"];?>?Action=Edit&CusID=<?=$objResult["
UserID
"];?>"
>Edit</a></td>
102.
<td align=
"right"
><a href=
"JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["
PHP_SELF
"];?>?Action=Del&CusID=<?=$objResult["
UserID
"];?>';}"
>
Delete
</a></td>
103.
</tr>
104.
<?
105.
}
106.
?>
107.
<?
108.
}
109.
?>
110.
<tr>
111.
<td><div align=
"center"
></div></td>
112.
<td><input type=
"text"
name=
"txtAddName"
size=
"20"
></td>
113.
<td><input type=
"text"
name=
"txtAddEmail"
size=
"20"
></td>
114.
<td><div align=
"center"
><input type=
"text"
name=
"txtAddAge"
size=
"2"
id=
"txtAddAge"
></div></td>
115.
<td colspan=
"2"
align=
"right"
><input name=
"btnAdd"
type=
"button"
id=
"btnAdd"
value=
"Add"
onClick=
"frmMain.hdnCmd.value='Add';frmMain.submit();"
></td>
116.
</tr>
117.
</table>
118.
</form>
119.
<?
120.
mysql_close();
121.
?>
122.
</body>
123.
</html>