初写 学生管理系统(初学者记录)
1.后台登陆页面
<?php
try {
$o="mysql:host=127.0.0.1;dbname=testx";
$username="root";
$password="root";
$pdo=new pdo($o,$username,$password);
$sql="select * from admin";
// echo $sql;
$res=$pdo->query($sql);
// var_dump($res);
// die;
} catch (Exception $e) {
echo $e->getmessage();
}
if (isset($_POST)&& !empty($_POST)) {
foreach ($res as $k => $v) {
if ($_POST["username"]==$v["user"] && $_POST["password"]==$v["password"]) {
header("location:http://www.azey.com/xt/dl.php");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>后台登陆系统</title>
</head>
<body>
<center>
<form method="post" type="none" action="">
<ul type="none" style="margin-top: 200px;">
<li>
<label>Id:</label>
<input type="text" name="username">
</li>
<li style="margin-top: 10px;">
<label>Password:</label>
<input type="password" name="password" style="margin-left: 12px;mar">
</li>
<li>
<label> </label>
<input type="submit" name="login" value="登录" style="margin-left: 50px;margin-top: 20px;">
</li>
</ul>
</form>
</center>
</body>
</html>
2.
Gn.php(样式页)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
text-decoration: none;
}
a{
font-family: "微软雅黑";
font-size: 20px;
color: black;
font-weight: bold;
}
</style>
</head>
<body>
<center>
<h2 style="">Student information management</h2>
<a style="color: white;font-weight: bold;" href="hasaki4.php">Increase students</a>
<br>
<a style="color: white;font-weight: bold;" href="hasaki2.php">Return</a>
<hr style="color: black;" />
</center>
<center>
<a href="nan.php">Man</a>
<a href="nv.php">Woman</a>
</center>
</body>
</html>
3.主页面
<?php
include_once "Gn.php";
try {
$o="mysql:host=127.0.0.1;dbname=testx";
$username="root";
$password="root";
$pdo=new pdo($o,$username,$password);
$sql="select * from lb";
// echo $sql;
$res=$pdo->query($sql);
// var_dump($res);
} catch (Exception $e) {
echo $e->getmessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<head>
<title>Student information management system</title>
</head>
<body bgcolor="#169FE9">
<center>
<h3>PHP1804 student information browsing</h3>
<table width="600" border="1">
<th>ID</th>
<th>Name</th>
<th>Sex</th>
<th>Age</th>
<th>Class</th>
<th>add & del</th>
<?php foreach ($res as $k => $v){?>
<tr style="text-align: center;">
<td><?php echo $v['id'] ?></td>
<td><?php echo $v['name'] ?></td>
<td><?php echo $v['sex'] ?></td>
<td><?php echo $v['age'] ?></td>
<td><?php echo $v['class'] ?></td>
<td>
<a href="http://www.azey.com/po/hasaki3.php?id='<?php echo $v["id"] ?>'">Delete</a>
<br>
<a href="hasaki5.php?id='<?php echo $v["id"] ?>'">Modify</a>
</td>
</tr>
<?php }?>
</center>
</body>
</html>
4.添加
<?php
error_reporting(0);
try {
$o="mysql:host=127.0.0.1;dbname=testx";
$username="root";
$password="root";
$pdo=new pdo($o,$username,$password);
$sql="insert into Lb (name,sex,age,class) values ('".$_POST['name']."',".$_POST['sex'].",".$_POST['age'].",".$_POST['class'].")";
// echo $sql;
$res=$pdo->query($sql);
// var_dump($res);
} catch (Exception $e) {
echo $e->getmessage();
}
?>
<html>
<head>
<title>Student information management</title>
</head>
<body bgcolor="#169FE9">
<center>
<?php include_once "Gn.php"; ?>
<h3>Add student information</h3>
<form id="addstu" name="addstu" method="post" action="">
<table>
<tr>
<td>Name</td>
<td><input id="name" name="name" type="text"/></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="1"/> Man
<input type="radio" name="sex" value="2"/> Woman
</td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" id="age"/></td>
</tr>
<tr>
<td>Class</td>
<td><input id="class" name="class" type="text"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="提交"/>
<input type="reset" value="重置"/>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
5.删除
<?php
try {
$o="mysql:host=127.0.0.1;dbname=testx";
$username="root";
$password="root";
$pdo=new pdo($o,$username,$password);
$sql="delete from lb where id=".$_GET['id'];
// echo $sql;
$res=$pdo->query($sql);
// var_dump($res);
} catch (Exception $e) {
echo $e->getmessage();
}
?>
6.修改
<?php
try {
$o="mysql:host=127.0.0.1;dbname=testx";
$username="root";
$password="root";
$pdo=new pdo($o,$username,$password);
$sql = "update Lb set name = '".$_POST['name']."',sex=".$_POST['sex'].",age=".$_POST['age'].",class=".$_POST['class']." where id=".$_GET['id'];
// echo $sql;
$res=$pdo->query($sql);
// var_dump($res);
} catch (Exception $e) {
echo $e->getmessage();
}
header("location:http://www.azey.com/xt/dl.php");
?>
<center>
<?php
include_once "Gn.php";
?>
</center>
<!DOCTYPE html>
<html>
<head>
<title>Student information management system</title>
<meta charset="utf-8">
</head>
<body bgcolor="#169FE9">
<center>
<form action="" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Name</td>
<td><input id="name" name="name" type="text" value=" <?php echo $rre['name'] ?> " /></td>
</tr>
<tr>
<?php if ($rre['sex']==1) { ?>
<td>Sex</td>
<td><input type="radio" name="sex" value="1"checked/> Man
<input type="radio" name="sex" value="2"/> Woman
</td>
<?php }else if($rre['sex']==2) { ?>
<td>Sex</td>
<td><input type="radio" name="sex" value="1"/> Man
<input type="radio" name="sex" value="2"checked/> Woman
</td>
</tr>
<?php } ?>
<tr>
<td>Age</td>
<td><input type="text" name="age" id="age" value="<?php echo $rre['age']; ?>"/></td>
</tr>
<tr>
<td>Class</td>
<td><input id="class" name="class" type="text" value="<?php echo $rre['class']; ?>"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="提交"/>
<input type="reset" value="重置"/>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
初学者 请多多包涵.