SQL server项目实战php+apache+SQL server

SQL server项目实战php+apache+SQL server

参考SQL server2012教程后的实习源码

开发环境:eclipse
PHP语言 PHP7.4
SQL server:2019
需要插件:SQLSRV58.EXE(连接SQL server和PHP)或以上
不多废话,源码如下:
index.html

<html>
<head>
<title>学生管理系统</title>
</head>
<body topMargin="0" leftMargin="0" bottomMargin="0" rightMargin="0">
<table width="675" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="1.png" width="790" height="97"></td>
</tr>
<tr>
<td><iframe src="mian_frame.html" width="790" height="313"></iframe></td>
</tr>
<tr>
<td><img src="2.png" width="790" height="32"></td>
</tr>
</table>
</body>
</html>>

login.php

<html>
<head>
<title>用户登陆</title>

</head>
<body bgcolor="D9DFAA">
<form action="" method="post">
<table bgcolor="D9DFAA">
<tr>
  <td>姓名</td>
  <td><input type="text" name="xm"></td>
  </tr>
   
  <tr>
  <td>口令</td>
  <td><input type="password" name="k1"></td>
  </tr>
  <tr>
  <td></td>
  <td align="right"><input type="submit" name="btn_lgn" value="登陆"></td>
  </tr>
  </table>
  <?php 
 
     include "fun.php";
     
     if(isset($_POST['btn_lgn']))
     {
         $xm=$_POST['xm'];
         $k1=$_POST["k1"];
        // $xh=$_POST['xh'];
         if($xm=="teacher"){
         
             if($k1=="123"){
                
                 header("location:teacher_main.php");
               
             }
             else 
                 echo "口令错";
             
         }
         else 
         {
             $sql="select * from xsb where XM='$xm'";
             $result=sqlsrv_query($conn, $sql);
             if($row=sqlsrv_fetch_array($result)){
             if(($row['KL']==$k1))
             {
                 session_start();
                 $_SESSION['xm']=$xm;
               //  $_SESSION['xh']=$xh;
                 header("location:student_main.php");
                    
                 
             }
             else {
                 echo "\n口令错\n";
                 echo gettype($k1);
                 echo gettype($row['KL']);
                 echo $k1;
                 echo $row['KL'];
                
                 
             }
             
         }
         else 
             echo "没有该用户";
         }
     }
  
  

  
  
  ?>
</form>
</body>
</html>

student_main.php

<html>
<head>
<title>学生功能选择</title>
</head>
<body bgcolor="D9DFAA">
<table bgcolor="D9DFAA" width="200" height="85">
<tr>
  <td align="center"><input type="button" value="修改口令" onclick=parent.frmmain.location="updateKL.php"></td>
  </tr>
  <tr>
  <td align="center"><input type="button" value="查询成绩" onclick=parent.frmmain.location="stuQuery.php"></td>
  </tr>
</table>
</body>
</html>

main_frame.html

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=GB2312"/>
<title>学生成绩管理系统 </title>
</head>
<frameset cols="215,*">
<frame frameborder=0 src="login.php" name="frmleft" scrolling="no" noresize>
<frame frameborder=0 src="body.html" name="frmmain" scrolling="no" noresize>
</frameset>
</html>

body.html

<html>
<head>
<title>content 网页</title>

</head>
<body topMargin="0" leftMargin="0" bottomMargin="0" rightMargin="0">
<img src="3.png" width="678" height="500">

  </body>

</html>

fun.php

<?php


$serverName="localhost";
$connectionInfo=array("Database"=>"PXSCJ","ConnectionPooling"=>false);
$conn= sqlsrv_connect($serverName,$connectionInfo);
if($conn==false)
{
    echo "连接失败";
        die( print_r(sqlsrv_errors(),true));
}
else 
    echo "success";
?>

stuInsDel.php

<html>
<head>
<title>增减学生</title>
</head>
<body bgcolor="D9DFAA">
<form method="post">
<table bgcolor="D9FAA">
<tr>
  <td align="left">姓名<input type="text" name='xm'><input name="btn" type="submit" value="加入"><input name="btn"
  type="submit" value="删除" ></td>
  <td><input type="file" name="file"></td>
  </tr>
  <tr>
  <td align="left">
  <?php 
  include "fun.php";
  $stu_sql="select * from xsb";
  $result=sqlsrv_query($conn, $stu_sql);
  echo "<table border=1>";
  echo "<tr bgcolor=#CCCCC0>";
  echo "<td align=center>学号</td><td align=center>口令<td>姓名</td></tr>";
  while($row=sqlsrv_fetch_array($result))
  {
      list($XM,$KL,$SNO)=$row;
      echo "<tr><td>$XM&nbsp;</td><td><input type=password value=$KL&nbsp; disabled></td><td align= center>$SNO</td></tr>";
      
      
  }
  echo "</table>";
  

  
  
  ?>
  
  </td>
  </tr>
  </table>
  </form>
  </body>
  </html>
  <?php 
  $xm=$_POST['xm'];
  $_SESSION['xm']=$xm;
  $stu_sql="select * from xsb where XM='$xm'";
  $result=sqlsrv_query($conn, $stu_sql);
  if(@$_POST["btn"]=='加入')
  {
      if($row=sqlsrv_fetch_array($result)){
          echo "\n该生已加入";
          
      }
      else {
          $insert_sql="insert into xsb(XM,KL,SNO) values('$xm','666','191320')";
          $insert_result=sqlsrv_query($conn, $insert_sql);
          if(sqlsrv_rows_affected($insert_result)>0)
              echo "<script>alert('添加成功!');location.herf='stuInsDel.php';</script>";
          else
              echo "<script>alert('添加失败!');location.herf='stuInsDel.php';</script>";
      }
      
      
      
      
  }
     if(@$_POST["btn"]=='删除')
     {
         if($row=sqlsrv_fetch_array($result)){
             $delete_sql="delete from xsb where XM='$xm'";
             $delete_result=sqlsrv_query($conn, $delete_sql);
             if(sqlsrv_rows_affected($insert_result)>0)
                 echo "<script>alert('删除成功!');location.herf='stuInsDel.php';</script>";
             else 
                 echo "<script>alert('删除成功!');location.herf='stuInsDel.php';</script>";
             
         }
         
         else  
             echo "<script>alert('该记录不存在!');location.herf='stuInsDel.php';</script>";
         
         
     }
  
  
  
  
  ?>

stuQuery.php

<html>
<head>
<title>查询成绩</title>
</head>
<body bgcolor="D9DFAA">
<?php 
session_start();
$xm=@$_SESSION['xm'];
$xh=@$_SESSION['xh'];
?>
<table bgcolor="D9DFAA">
<tr>
<td align="left">姓名<input type="text" name="xm" value="<?php 
echo $xm;

?>"disabled></td>
</tr>
<tr>
<td align="left">
<?php 
include "fun.php";
$cj_sql="select CNA,grade from cjb,kcb,xsb
where XM='WL'AND cjb.SNO=xsb.SNO AND cjb.CNO=kcb.CNO";
$result=sqlsrv_query($conn, $cj_sql);
//$xmcj_sql="select * from cjb";
//$cj_rs=sqlsrv_query($conn, $result);
echo "<table border=1>";
echo "<tr bgcolor=#CCCCC0>";
    echo "<td>课程名</d><td align=center>成绩</td></tr> ";
    while($row=sqlsrv_fetch_array($result)){
        list($KC,$CJ)=$row;
        echo "<tr><td>$KC&nbsp;</td><td align=center>$CJ</td></tr>";
        
        
    }
    echo "</table>";

?>
</td>
<td align="center">

</td>
</tr>
</table>
</body>
</html>







teacher_main.php

<html>
<head>
<title>教师功能选择</title>
</head>
<body bgcolor="D9DFAA">
<table bgcolor="D9DFAA" width="200" height="85">
<tr>
  <td align="center"><input type="button" value="增减学生" onclick=parent.frmmain.location="stuInsDel.php"></td>
  </tr>
  <tr>
  <td align="center"><input type="button" value="输入成绩" onclick=parent.frmmain.location="cjInsDel.php"></td>
  </tr>
</table>
</body>
</html>

UpdateKL.php

<html>
<head>
<title>修改口令</title>
</head>
<body bgcolor="D9DFAA">
<?php 
session_start();
$xm=@$_SESSION['xm'];
?>
<form action="" method="post">
<table bgcolor="D9DFAA">
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input type="text" name="newkl"></td>
</tr>
<tr>
<td>重新输入新口令</td>
<td><input type="text" name="renewkl"></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="btn_confirm" value="确认"></td>
</tr>
</table>
<?php 
if(isset($_POST['btn_confirm'])){
    include "fun.php";
    $newkl=$_POST['newkl'];
    $renewkl=$_POST['renewkl'];
    if($newkl==$renewkl){
        $update_sql="update xsb set KL='$newkl' where XM='$xm'";
        $result=sqlsrv_query($conn, $update_sql);
        if(sqlsrv_rows_affected($result>0))
            echo "修改成功";
        else 
        { echo "修改成功";
       // echo  sqlsrv_rows_affected($result);
        }
        
        
        
    }
    else 
        echo "两次输入不一致";
    
    
    
    
    
}





?>
</form>
</body>
</html>



cjInsDel.php

<html>
<head>
<title>输入成绩</title>
</head>
<body bgcolor="D9DFAA">
<form method="post">
<table bgcolor="D9FAA">
<tr>
  <td align="left">课程号<input type="text" name='kc'></td>
  </tr>
  
  <tr>
  <td align="left">&nbsp;&nbsp;<input type="text" name="xm"><input name="btn" type="submit" value="查询"></td>
  </tr>
  <tr>
  <td align="left">&nbsp;&nbsp;<input type="text" name="cj"><input name="btn" type="submit" value="加入"><input name="btn" type="submit" value="删除"></td>
  </tr>
  <tr><td align="left">
  <?php 
  include 'fun.php';
  if(@$_POST["btn"]=='查询'){
      
      $kc=$_POST['kc'];
      $xm=$_POST['xm'];
      if(($kc!="")&&($xm!="")){
          $cj_sql="select xsb.SNO,XM,kcb.CNA,grade,cjb.CNO from cjb, xsb, kcb where cjb.CNO='$kc' and cjb.SNO='$xm'and xsb.SNO=cjb.SNO and kcb.CNO=cjb.CNO;";
          
          
      }
      elseif($kc!=""){
          $cj_sql="select xsb.SNO,XM,kcb.CNA,grade,cjb.CNO from cjb, xsb, kcb where cjb.CNO='$kc' and kcb.CNO=cjb.CNO and cjb.SNO=xsb.SNO";
          
          
          
      }
      elseif ($xm!=""){
          
          $cj_sql="select xsb.SNO,XM,kcb.CNA,grade,cjb.CNO from cjb, xsb, kcb where cjb.SNO='$xm' and kcb.CNO=cjb.CNO and cjb.SNO=xsb.SNO";
          
      }
      else 
          echo "<script>alert('请输入查询条件!');location.herf='cjInsDel.php';</script>";
      
      
      
      
  }
  else 
  {
      
      $cj_sql="select cjb.SNO,xsb.XM,kcb.CNA,grade,cjb.CNO from cjb, xsb, kcb where cjb.CNO=kcb.CNO and cjb.SNO=xsb.SNO";
      
      
  }
  $result=sqlsrv_query($conn, $cj_sql);
  echo "<table border=1>";
  echo "<tr bgcolor=#CCCCC0>";
  echo "<td align=center>学号</td><td align=center>姓名</td><td align=center>课程名</td><td align=center>成绩</td><td>课程号</td></tr> ";
  while($row=sqlsrv_fetch_array($result))
  {
      list($XM,$CNA,$grade,$XH,$CNO)=$row;
      echo "<tr><td>$XM&nbsp;</td><td>$CNA&nbsp;</td><td>$grade&nbsp;</td><td>$XH&nbsp;</td><td align=center>$CNO</td></tr>";
      
      
      
  }
  echo "</table>";
  
  
  
  
  
  
  
  ?>
  
  </td></tr>
  </table>
  </form>
  </body>
  </html>
  <?php 
  $kc=$_POST['kc'];
  $xm=$_POST['xm'];
  $cj=$_POST['cj'];
  $cj_sql="select * from cjb, xsb, kcb where cjb.CNO='$kc' and cjb.SNO='$xm'and xsb.SNO=cjb.SNO and kcb.CNO=cjb.CNO;";
  $result=sqlsrv_query($conn, $cj_sql);
  if(@$_POST["btn"]=="加入"){
      
      if($row=sqlsrv_fetch_array($result))
          echo "<script>alert('已存在该记录');location.herf='cjInsDel.php';</script>";
          else{
              $insert_sql="insert into cjb(SNO,CNO,grade) values('$xm','$kc','$cj')";
              $insert_result=sqlsrv_query($conn, $insert_sql);
              if(sqlsrv_rows_affected($result>0))
                  echo "<script>alert('添加成功');location.herf='cjInsDel.php';</script>";
              
              else 
                  echo "<script>alert('添加成功');location.herf='cjInsDel.php';</script>";
          }
      
  }
  if(@$_POST["btn"]=="删除")
  {
      if($row=sqlsrv_fetch_array($result))
      {
          $delete_sql="delete from cjb where SNO='$xm' and CNO='$kc' ";
          $delete_result=sqlsrv_query($conn, $delete_sql);
          if(sqlsrv_rows_affected($insert_result)>0)
              echo "<script>alert('删除成功');location.herf='cjInsDel.php';</script>";
          else 
              echo "<script>alert('删除成功');location.herf='cjInsDel.php';</script>";
          
      }
      else
          echo "<script>alert('不存在该条记录');location.herf='cjInsDel.php';</script>";
      
      
  }
  
  
  
  ?>
  
   
  
  

数据库主要建三个表,课程表,学生表,成绩表,具体去看SQL server2012教程的附录,上边有具体的规定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值