查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>查询</title>
<style>
h1,form{
text-align: center;
}
table{
margin: auto;
border: 2px solid blue;
}
table{
margin:auto;
border:2px solid blue;
}
tr:nth-child(odd){
background: #ccc;
}
tr:nth-child(even){
background: yellow;
}
.form01{
margin:auto;
height: 74px;
}
</style>
<script>
function check1(){
var db = document.getElementById("bd");
db.action = "./insert.php";
db.submit();
}
function check2(){
var db = document.getElementById("bd");
db.action = "./update.php";
db.submit();
}
function check3(){
var db = document.getElementById("bd");
db.action = "./delete.php";
db.submit();
}
</script>
</head>
<body>
<h1>所有老师信息</h1>
<div class="form01">
<form action='./index.php' method='post'>
<input type='text' name='query'/>
<input type='submit' name='btnQuery' value='搜索'/>
</form>
<br/>
<form action='' method='post' id='bd'>
<input type='submit' name='insert' value='新增' onclick='check1()'>
<input type='submit' name='' value='编辑' onclick='check2()'>
<input type='submit' name='delete' value='删除' onclick='check3()'>
</div>
<table border="1" width='600px' style='text-align:center;'>
<tr>
<td></td>
<td>工号</td>
<td>姓名</td>
<td>性别</td>
<td>出生日期</td>
<td>所在部门</td>
</tr>
<?php
$query = $_POST['query'];
//$_SESSION['query']="$query";
$db = new mysqli("localhost", "root","123456","studentmis");
if(!$db)
{
echo "数据库连接失败!!!";
}
if(isset($_POST['btnQuery']) && $query != null)
{
//session_start();
$sql="SELECT laoshi.e_id,laoshi.e_name, laoshi.sex, laoshi.date_birth, bumen.dept_name
from laoshi left join bumen on bumen.dept_no = laoshi.dept_no WHERE laoshi.e_id = '$query' or laoshi.e_name = '$query' or bumen.dept_name = '$query'";
}else{
$sql="SELECT e_id,e_name, sex, date_birth, bumen.dept_name from laoshi left join bumen on bumen.dept_no = laoshi.dept_no";
}
$db->query("SET NAMES utf8");
$res=$db->query($sql);
?>
<?php
if($res){

while($row=$res->fetch_assoc()) {
$gonghao=$row['e_id'];
$xingming=$row['e_name'];
$sex=$row['sex'];
$shengri=$row['date_birth'];
$suozaibumen=$row['dept_name'];

echo "<center><tr><td><input type='checkbox' name='sel[]' value='".$row["e_id"]."'/></td></center>".
"<td>$gonghao</td>
<td>$xingming</td>
<td>$sex</td>
<td>$shengri</td>
<td>$suozaibumen</td>
</tr>";
}

//释放结果集
$res->close;
}
//关闭连接
$db->close();
?>
</table>
</form>
</body>
</html>

新增

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>新增</title>
<style type="text/css">
.css-01
{
width: 100px;
height: 50px;
margin: 200px auto;
}
</style>
<script type="text/javascript">
function myCheck()
{//遍历所有表单元素
for(var i=0;i<document.form1.elements.length-1;i++)
{//判断所有表单值是否为空
if(document.form1.elements[i].value=="")
{
alert("当前表单不能有空项");
//将光标定位在空表单处
document.form1.elements[i].focus();
return false;
}
}
return true;
}
</script>

</head>
<body>
<div class="css-01">
<form action="./insert.php" name="form1" method="post" onSubmit="return myCheck()">
<input type="text" name="id" placeholder="ID">
<input type="text" name="name" placeholder="姓名">
<input type="text" name="birthday" placeholder="生日">
<?php
echo "<select name='department'>";
$db = new mysqli("localhost","root","123456","studentmis");
$sql = "SELECT * FROM bumen WHERE dept='xinguan'";
$db->query("SET NAMES utf8");
$data = $db->query($sql);
if($data){
while($row = $data->fetch_assoc()) {
$bumen_id = $row['dept_no'];
$bumen_name = $row['dept_name'];
echo "<option name='bumen' value='$bumen_id'>$bumen_name</option>";
//echo "<input type='text' name='department' placeholder='部门'>";
}
}
echo "</select>";
?>
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女
<input type="submit" name="submit" value="新增">
</form>
</div>
<?php
if(isset($_POST['submit'])){
$id = $_POST["id"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$birthday = $_POST["birthday"];
$department = $_POST["department"];
$db = mysqli_connect("localhost", "root","123456","studentmis");
if(!$db){
echo "数据库连接失败!!!";
}
$mysql = "INSERT INTO laoshi VALUES ('$id','$name','$sex','$birthday','$department')";
mysqli_query($db,"SET NAMES utf8");
$data = mysqli_query($db,$mysql);
if ($data) {
echo "<script>alert('添加成绩成功');this.location.href='index.php'</script>";
} else {
echo "<script>alert('添加成绩失败')</script>";
}
mysqli_close($db);
}
?>
</body>
</html>

删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>删除</title>
</head>
<body>
<?php
if(count($_POST['sel']) == 0){
echo "<script>alert('请先选择需要删除或修改的老师信息!');history.go(-1);</script>";
}else{
$db = new mysqli ("localhost", "root","123456","studentmis");
if(!$db){
echo "数据库连接失败!!!";
}
for($i=0;$i<count($_POST['sel']);$i++){
$sqlDel ="DELETE FROM laoshi WHERE e_id='".$_POST['sel'][$i]."'";
$db->query($sqlDel);
}
echo "<script>alert('删除成功!');window.location='index.php';</script>";
$db->close();
}
?>
</body>
</html>

更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Conter-Type" content="text/html; charset=utf8"/>
<title>更新</title>
</head>
<body>
<?php
if(count($_POST['sel'])==0 && !isset($_POST['update'])) //判断是否选择了要删除的选项,并且没有点击本页面的提交按钮
{
echo "<script>alert('请先选择需要删除或修改的老师信息!');history.go(-1);</script>";
}
$db = new mysqli("localhost","root","123456","studentmis");
if($db->connect_error)
{
echo "数据库连接失败!!!";
}
if(isset($_POST['update'])){ //点击按钮执行更新
$gonghao = $_POST["text1"];
$xingming = $_POST["text2"];
$shengri = $_POST["text3"];
$bumen = $_POST["department"];
$sex = $_POST["sex"];

$sql = "UPDATE laoshi SET e_id='$gonghao',e_name='$xingming',sex='$sex',date_birth='$shengri',dept_no='$bumen' WHERE e_id='$gonghao'";
$db->query('SET NAMES UTF8');
$result = $db->query($sql);
if ($result) {
echo "<script>alert('更新成功');this.location.href='index.php'</script>";
} else {
echo "<script>alert('更新失败')</script>";
}
}else{ // 查询要更新的数据
for($i=0;$i<count($_POST['sel']);$i++){
$sqlDel ="SELECT e_id,e_name, sex, date_birth,dept_no
FROM laoshi WHERE e_id='".$_POST['sel'][$i]."'";
$db->query('SET NAMES UTF8');
$res=$db->query($sqlDel);
if($res){
while($row=$res->fetch_assoc())
{
$gonghao=$row['e_id'];
$xingming=$row['e_name'];
$sex=$row['sex'];
$shengri=$row['date_birth'];
$suozaibumen=$row['dept_no'];
}
echo "<form action='./update.php' method='post'>";
echo "<div style='margin: 200px auto;width: 100px;height: 50px;'>
<input type='text' placeholder='工号' name='text1' value='$gonghao' readonly='readonly'>
<br>
<input type='text' placeholder='姓名' name='text2' value='$xingming'>
<br>
<input type='text' placeholder='生日' name='text3' value='$shengri'>
<br>";
// 下拉框
echo "<select name='department'>";
$sql = "SELECT * FROM bumen WHERE dept='xinguan'";
$db->query("SET NAMES utf8");
$data = $db->query($sql);
if($data){
while($row = $data->fetch_assoc()) {
$bumen_id = $row['dept_no'];
$bumen_name = $row['dept_name'];
if($bumen_id == $suozaibumen){
echo "<option name='bumen' value='$bumen_id' selected>$bumen_name</option>";
}else{
echo "<option name='bumen' value='$bumen_id'>$bumen_name</option>";
}

}
}
echo "</select>";

if($sex == "男")
{
echo "<input type=radio name=sex value='男' checked>男";
echo "<input type=radio name=sex value='女'>女";
}
else
{
echo "<input type=radio name=sex value='男'>男";
echo "<input type=radio name=sex value='女' checked>女";
}
echo "<br>";
echo "<input type='submit' name='update' value='提交'>";
echo "</div>";
echo "</form>";
//释放结果集
$res->close;
}
//关闭连接
}
}
$db->close();
?>
</body>
</html>

双色球

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>双色球</title>
<style>
div {
width: 50px;
height: 50px;
border-radius: 50%;
text-align: center;
line-height: 50px;
float: left;
margin: 10px;
}
.red{
background-color: blue;
}
.blue{
background-color: red;
}
</style>
</head>
<body>
<?php
$num=range(1,10);//生成数组
$red=array_rand($num,4);//随机选多少个数
shuffle($red); //打乱数组
$blue=rand(1,10);//生成随机数

echo "<div class='blue'>$blue</div>";

foreach($red as &$value){
echo "<div class='red'>$value</div>";
}
?>
</body>
</html>

空心菱形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
//$n=5;
for($i=1;$i<=5;$i++){
//打印空格
for($j=1;$j<=5-$i;$j++){
echo " ";
}
//打印*号
for($k=1;$k<=2*$i-1;$k++){
//打印第一行后最后一行都打*连接($i==1 || $i==5)
if($i==1){ //去掉$i==5 把中间抛空
echo "*";
}else{
//怎么打空格和*号的问题
if($k==1 || $k==2*$i-1){
echo "*";
}else{
echo " ";
}
}
}
echo "<br/>";
}
//倒转 抛空
for($i=5;$i>=0;$i--){
//打印空格
for($j=0;$j<=5-$i;$j++){
echo " ";
}
//打印*号
for($k=1;$k<=2*$i-3;$k++){
//怎么打空格和*号的问题
if($k==2*$i-3 || $k==1){
echo "*";
}else{
echo " ";
}
}
echo "<br/>";
}
?>
</body>
</html>

登录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<form action="./denglu.php" method="post">
<input type="text" name="name" placeholder="用户名"/>
<input type="password" name="password" placeholder="密码"/>
<input type="submit" name="submit" value="登录" />
</form>
<?php
if(isset($_POST["submit"])){
$db = mysqli_connect("localhost","root","123456","teacher");
if(!$db){
echo "数据库连接失败!!!";
}
$name = $_POST["name"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE name='$name' and password='$password'";
mysqli_query($db,"SET NAMES utf8");
$data = mysqli_query($db,$sql);
$row=mysqli_num_rows($data);
if($row){
echo "登录成功。";
}else{
echo "账号密码错误!!!";
}
}
?>
</div>
</body>
</html>