Bey-Hey 2023-07-01 18:06 采纳率: 85.7%
浏览 6

php对数据库进行查找和修改操作失败

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" />&nbsp;星期:<input type="text" name="cweek" />&nbsp;<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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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."页"."&nbsp".$arp." | ". $anp."</p>";
?> 
   <!--
       输出总页码及当前页码、页码导航
   -->
</div>


数据库清单样式

img

修改代码


<?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>&nbsp;<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;
        }

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-07-01 20:41
    关注
    • 以下回答由chatgpt基于相关博客总结生成:

      问题背景: 您遇到了在使用PHP进行数据库查找和修改操作时的困难。

      问题描述: 您需要对数据库进行查找和修改操作,但无法成功执行,并希望能找到解决方法。

      解决方案:

      1. 确定使用的数据库管理系统: 请提供您使用的数据库管理系统,例如MySQL、Oracle等。

      2. 提供相关代码示例: 请提供一些与修改操作相关的代码示例,包括查询和修改的函数或方法。这样我们可以更好地理解您的代码并帮助您找到解决方法。

      3. 确定数据库清单的展示样式: 请提供您希望数据库清单以何种样式展示,例如表格、列表等。

      根据提供的信息,我们可以进一步分析问题并提供解决方法。请提供以上信息后,我将尽力帮助您解决问题。

    评论

报告相同问题?

问题事件

  • 修改了问题 7月1日
  • 创建了问题 7月1日

悬赏问题

  • ¥15 jscolor 赋值input 没能引起前边色框的颜色变化
  • ¥100 驱动程序在\device\raidport1 上检测到控制器错误
  • ¥15 JS报错变量未定义,如何解决?
  • ¥20 找辅导 初学者 想实现一个项目 没有方向
  • ¥15 研究方向遥感场景识别分类。求深度学习基础课程
  • ¥15 关于渗漏场的电场分布模拟
  • ¥24 matlab怎么修改仿真初始时间
  • ¥15 两分段线性回归模型分析阈值效应
  • ¥15 前端和后端代码都没报错,但是点登录没反应的?
  • ¥100 需要远程解决QSQLITE问题!