<?php
if ($_POST["act"]=="login"){
$db_link=mysql_connect("localhost","root","db123456");
$db_sel=mysql_select_db("kkdb");
$str_sel="SELECT * FROM `tblmen` WHERE `accnt`= '".$_POST["accnt"]."' AND `pwd`='".$_POST["pwd"]."'";
$result=mysql_query($str_sel);
$data_cnt=mysql_num_rows($result);
if ($data_cnt==1){
header("Location:list.php");
}else{
header("Location:index.php");
}
}
?>
<html>
<head></head>
<body>
<h1 align="center">會員登入</h1>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="login" name="act">
<input type="submit" value="登入" name="ok">
</td></tr>
</table>
</form>
</body>
</html>
+++++++++++++++++++++++++++++
# vi /var/www/html/list.php
<?php
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
$str_sel="select * from tblmen";
$result=mysql_query($str_sel);
?>
<html>
<head></he/ad>
<body>
<h1 align="center">學生系統</h1>
<p align="center"><a href="add.php">新增學生資料</a> <a href="query.php">查詢學生資料</a></p>
<table align="center">
<tr><td>編號</td><td>名字</td><td>帳號</td><td>密碼</td></tr>
<?php
while ($tbl_rows=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$tbl_rows["mid"]."</td>";
echo "<td>".$tbl_rows["na"]."</td>";
echo "<td>".$tbl_rows["accnt"]."</td>";
echo "<td>".$tbl_rows["pwd"]."</td>";
echo "<td><a href='update.php?mid=".$tbl_rows["mid"]."'>修改</a></td>";
echo "<td><a href='delete.php?mid=".$tbl_rows["mid"]."'>刪除</a></td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
++++++++++++++++++++++++++++++++++++
# vi /var/www/html/add.php
<?php
if ($_POST["act"]=="add"){
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
$str_insert="INSERT INTO `tblmen`(`mid`, `na`, `accnt`, `pwd`) VALUES ('".$_POST["mid"]."','".$_POST["na"]."','".$_POST["accnt"]."','".$_POST["pwd"]."')";
mysql_query($str_insert);
header("Location:list.php");
}
?>
<html>
<head></head>
<body>
<h1 align="center">新增資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid"></td></tr>
<tr><td>名字</td><td><input type="text" name="na"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="add" name="act">
<input type="submit" value="新增" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>
if ($_POST["act"]=="add"){
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
$str_insert="INSERT INTO `tblmen`(`mid`, `na`, `accnt`, `pwd`) VALUES ('".$_POST["mid"]."','".$_POST["na"]."','".$_POST["accnt"]."','".$_POST["pwd"]."')";
mysql_query($str_insert);
header("Location:list.php");
}
?>
<html>
<head></head>
<body>
<h1 align="center">新增資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid"></td></tr>
<tr><td>名字</td><td><input type="text" name="na"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="add" name="act">
<input type="submit" value="新增" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>
++++++++++++++++++++++++++
# vi /var/www/html/update.php
<?php
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
if ($_POST["act"]=="update"){
$str_update="UPDATE `tblmen` SET `na`='".$_POST["na"]."',`accnt`='".$_POST["accnt"]."',`pwd`='".$_POST["pwd"]."' WHERE `mid` ='".$_POST["mid"]."'";
mysql_query($str_update);
header("Location:list.php");
}
$str_sel="SELECT * FROM `tblmen` WHERE `mid`='".$_GET["mid"]."'";
//echo $str_sel;
$result=mysql_query($str_sel);
$tbl_rows=mysql_fetch_assoc($result);
?>
<html>
<head></head>
<body>
<h1 align="center">修改資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formUpdate">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid" value="<?php echo $tbl_rows["mid"]; ?>" disabled></td></tr>
<tr><td>名字</td><td><input type="text" name="na" value="<?php echo $tbl_rows["na"]; ?>"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt" value="<?php echo $tbl_rows["accnt"]; ?>"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd" value="<?php echo $tbl_rows["pwd"]; ?>"></td></tr>
<tr><td></td><td>
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
if ($_POST["act"]=="update"){
$str_update="UPDATE `tblmen` SET `na`='".$_POST["na"]."',`accnt`='".$_POST["accnt"]."',`pwd`='".$_POST["pwd"]."' WHERE `mid` ='".$_POST["mid"]."'";
mysql_query($str_update);
header("Location:list.php");
}
$str_sel="SELECT * FROM `tblmen` WHERE `mid`='".$_GET["mid"]."'";
//echo $str_sel;
$result=mysql_query($str_sel);
$tbl_rows=mysql_fetch_assoc($result);
?>
<html>
<head></head>
<body>
<h1 align="center">修改資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formUpdate">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid" value="<?php echo $tbl_rows["mid"]; ?>" disabled></td></tr>
<tr><td>名字</td><td><input type="text" name="na" value="<?php echo $tbl_rows["na"]; ?>"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt" value="<?php echo $tbl_rows["accnt"]; ?>"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd" value="<?php echo $tbl_rows["pwd"]; ?>"></td></tr>
<tr><td></td><td>
<input type="hidden" value="<?php echo $tbl_rows["mid"]; ?>" name="mid">
<input type="hidden" value="update" name="act">
<input type="submit" value="更新" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>
+++++++++++++++++++++++++++++++++
# vi /var/www/html/query.php
<html>
<head></head>
<body>
<h1 align="center">會員查詢</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formQuery">
<table align="center">
<tr><td>姓名</td><td><input type="text" name="na"></td><td></td><td></td></tr>
<tr><td></td><td>
<input type="hidden" value="query" name="act">
<input type="submit" value="查詢" name="ok">
</td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td>編號</td><td>姓名</td><td>帳號</td><td>密碼</td></tr>
<?php
if ($_POST["act"]=="query"){
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
$str_sel="SELECT * FROM `tblmen` WHERE `na` LIKE '%".$_POST["na"]."%'";
//echo $str_sel;
$result=mysql_query($str_sel);
$data_cnt=mysql_num_rows($result);
if ($data_cnt!=0){
while ($tbl_rows=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$tbl_rows["mid"]."</td>";
<head></head>
<body>
<h1 align="center">會員查詢</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formQuery">
<table align="center">
<tr><td>姓名</td><td><input type="text" name="na"></td><td></td><td></td></tr>
<tr><td></td><td>
<input type="hidden" value="query" name="act">
<input type="submit" value="查詢" name="ok">
</td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td>編號</td><td>姓名</td><td>帳號</td><td>密碼</td></tr>
<?php
if ($_POST["act"]=="query"){
$db_link=mysql_connect("localhost","root","db123456");
mysql_query("SET NAMES 'utf8'");
$db_sel=mysql_select_db("kkdb");
$str_sel="SELECT * FROM `tblmen` WHERE `na` LIKE '%".$_POST["na"]."%'";
//echo $str_sel;
$result=mysql_query($str_sel);
$data_cnt=mysql_num_rows($result);
if ($data_cnt!=0){
while ($tbl_rows=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$tbl_rows["mid"]."</td>";
echo "<td>".$tbl_rows["na"]."</td>";
echo "<td>".$tbl_rows["accnt"]."</td>";
echo "<td>".$tbl_rows["pwd"]."</td>";
echo "</tr>";
}
}
}
?>
</table>
</form>
</body>
</html>
++++++++++++++++++++++++++++++++++
# vi /var/www/html/delete.php
<?php
$db_link=mysql_connect("localhost","root","db123456");
$db_sel=mysql_select_db("kkdb");
$str_del="DELETE FROM `tblmen` WHERE `mid`='".$_GET["mid"]."'";
$result=mysql_query($str_del);
?>
<html>
<head></head>
<body>
<h1 align="center">資料刪除完畢!</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
</body>
</html>