php对数据库进行查找和修改操作失败
数据库清单查找+修改
```php
<meta name="" charset="11" content="" />
<link rel="stylesheet" href="css/List.css" />
<div class="container">
<h1 align="center">各教室课表</h1>
<a href="Borrow.php"><input type="button" name="add" value="添加"/></a><hr />
<div class="form">
<form action="",menthod="post">
教室:<input type="text" name="cname" /> 星期:<input type="text" name="cweek" /> <input type="submit" name="search" value="搜索"/>
</form>
</div>
<?php
include "conn.php";
if(isset($_POST['search'])){
$cname=$_POST['cname'];
$cweek=$_POST['cweek'];
$p=1;
}
$sql="select * from tb_class where cname like '%{$cname}%' and cweek like '%{$cweek}%' ";
$data=$conn->query($sql);
$zs=$data->num_rows;//计算总数
$ps=5;//设置单页记录数
$pc=ceil($zs/$ps);//计算总页数
if(isset($_GET['p'])){
$p=$_GET['p'];//设置当前页
}else{
$p=1;
}
$n=($p-1)*$ps;//计算当前页
//预处理搜索关键字
$stmt=$conn->stmt_init();
$sql="select * from tb_class where cname like '%{$cname}%' and cweek like '%{$cweek}%' order by cname limit ?,?";
$stmt->prepare($sql);//准备sql语句
$stmt->bind_param("ii",$n,$ps);//绑定参数
$stmt->execute();//执行
$stmt->bind_result($cid,$cname,$cweek,$cstartsection,$cendsection,$cteacher,$cclass,$ccourse,$cstartweek,$cendweek);
$data=$conn->query($sql);
// echo $sql;
if($p>1){ //设置页码导航
$rp=$p-1;//前一页页码
$arp="<a href=?p=1>首页</a> | <a href=?p=$rp>上一页</a>";
}else{
$rp=$p;
$arp="首页";
}
if($p<$pc){ //设置页码导航
$np=$p+1;//后一页页码
$anp="<a href=?p=$np>下一页</a> | <a href=?p=$pc>尾页</a>";
}else{
$np=$p;
$anp="尾页";
}
$data=$conn->query($sql);//显示当前页数据
?>
<table align="center" width="800px" border="1"
style="border-collapse: collapse;">
<thead>
<th>序号</th>
<th>教室</th>
<th>星期</th>
<th>开始节数</th>
<th>结束节数</th>
<th>上课教师</th>
<th>上课班级</th>
<th>课程名称</th>
<th>开始周数</th>
<th>结束周数</th>
<th>操作</th>
</thead>
<?php while($row=$stmt->fetch()) { ?>
<tr>
<th><?php echo $cid ?></th>
<th><?php echo $cname ?></th>
<th><?php echo $cweek ?></th>
<th><?php echo $cstartsection ?></th>
<th><?php echo $cendsection ?></th>
<th><?php echo $cteacher ?></th>
<th><?php echo $cclass ?></th>
<th><?php echo $ccourse ?></th>
<th><?php echo $cstartweek ?></th>
<th><?php echo $cendweek ?></th>
<th><?php echo " <a href=ClassEdit.php?cid={$cid}>修改</a> | <a href=ClassDel.php?cid={$cid}>删除</a>"?></th>
</tr>
<?php } ?>
</table>
<?php echo "<br><p align=center>"."共".$zs."条记录," ."共".$pc."页,"."当前页为第".$p."页"." ".$arp." | ". $anp."</p>";
?>
<!--
输出总页码及当前页码、页码导航
-->
</div>
数据库清单样式
修改代码
<?php
include 'conn.php';
$cid=$_GET['cid'];
$sql="select * from tb_class where cid={$cid}";
// mysqli_query($sql);
// $row=mysqli_fetch_array($rs);
?>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/ManagerAdd.css" />
<div class="container">
<div class="Add-wrapper">
<form action="" method="post">
<div class="header">修改课表信息</div>
<div class="form-wrapper">
<input type="text" name="cid" placeholder="请输入新的编号" class="input-item" value="<?php echo $row['cid'];?>">
<p><input type="text" name="cname" placeholder="请输入更正班级名称" class="input-item" value="<?php echo $row['cname'];?>"</p>
<input type="text" name="cweek" placeholder="请输入新的星期" class="input-item" value="<?php echo $row['cweek'];?>">
<input type="number" name="cstartsection" placeholder="请输入新的开始节数" class="input-item" value="<?php echo $row['cstartsection'];?>">
<input type="number" name="cendsection" placeholder="请输入新的结束节数" class="input-item" value="<?php echo $row['cendsection'];?>">
<input type="text" name="cteacher" placeholder="请输入新的老师" class="input-item" value="<?php echo $row['cteacher'];?>">
<input type="text" name="ccourse" placeholder="请输入新的课程" class="input-item" value="<?php echo $row['ccourse'];?>">
<input type="text" name="cclass" placeholder="请输入新的班级" class="input-item" value="<?php echo $row['cclass'];?>">
<input type="number" name="cstartweek" placeholder="请输入新的开始周数" class="input-item" value="<?php echo $row['cstartweek'];?>">
<input type="number" name="cendweek" placeholder="请输入新的结束周数" class="input-item" value="$row['cendweek']">
<input type="button" name="edit" value="更新"></input> <a href="ClassList.php"><input type="button" name="cancle" value="返回"></input></a>
</div>
</form>
</div>
</div>
<?php
include 'conn.php';
if(isset($_POST['edit'])){
$cid=$_POST['cid'];
$cname=$_POST['cname'];
$cweek=$_POST['cweek'];
$cstartsection=$_POST['cstartsection'];
$cendsection=$_POST['cendsection'];
$cteacher=$_POST['cteacher'];
$ccourse=$_POST['ccourse'];
$cclass=$_POST['cclass'];
$cstartweek=$_POST['cstartweek'];
$cendweek=$_POST['cendweek'];
// mysqli_query($conn,"update tb_class set cid='{$cid}' cname='{$cname}',cweek='{$cweek}' where cid={$cid}");
$sql="update tb_class set cid=$cid name='{$cname}',cweek='{$cweek}',cstartsection=$cstartsection,cendsection=$cendsection,cteacher='{$cteacher}',ccourse='{$ccourse}',cstartweek=$cstartweek,cendweek=$cendweek where cid={$cid};";
mysqli_query($conn,$sql);
if($conn->affected_rows>0){
echo "<script>alert('修改记录成功。');location.href='ClassList.php';</script>";
}else{
echo "<script>alert('修改记录失败。');location.href='ClassList.php';</script>";
}
}
?>
附件:css'
List
```css
* {
margin: middle;
padding: middle;
}
.container {
height: auto;
background-color: pink;
}
.form{
align: center;
.wrapper {
background-color: #fff;
width: 358px;
height: 588px;
border-radius: 15px;
padding: 0 50px;
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.login-wrapper {
background-color: #fff;
width: 358px;
height: 588px;
border-radius: 15px;
padding: 0 50px;
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.header {
font-size: 38px;
font-weight: bold;
text-align: center;
line-height: 200px;
}
display: block;
width: 100%;
margin-bottom: 20px;
border: 0;
padding: 10px;
border-bottom: 1px solid rgb(128, 125, 125);
font-size: 15px;
outline: none;
}
.input-item:placeholder {
text-transform: uppercase;
}
.msg {
text-align: center;
line-height: 88px;
}
ManagerAdd
```css
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
body {
height: 100%;
}
.container {
height: 100%;
background-image: linear-gradient(to right, pink, pink);
}
.Add-wrapper {
background-color: #fff;
width: 400px;
height: 600px;
border-radius: 15px;
padding: 0 50px;
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.header {
font-size: 38px;
font-weight: bold;
text-align: center;
line-height: 100px;
}
.input-item {
display: block;
width: 100%;
margin-bottom: 20px;
border: 0;
padding: 5px;
border-bottom: 1px solid rgb(128, 125, 125);
font-size: 15px;
outline: none;
}
.input-item:placeholder {
text-transform: uppercase;
}
.button {
text-align: center;
padding: 10px;
width: 100%;
margin-top: 30px;
background-color: pink;
color: #fff;
border: solid 1px white;
}
.msg {
text-align: center;
line-height: 88px;
}
a {
text-decoration-line: none;
color: #abc1ee;
}