数据库课程设计(php+html+css)

这是一篇关于课程设计的博客,作者分享了使用PHP进行数据库连接的经验,并提供了部分代码示例,可供使用PHP进行网页开发的学习者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

折腾了很久的课程设计……既然上了优快云干脆也贴上来得了,如果以后有人和我用同一种语言,还能参考一下……

主要贴连接数据库的部分和首页。


数据库连接:

<?php @session_start();
	ini_set("display_errors","Off");
	ini_set("session.cookie_httponly", 1);   
	header('X-Frame-Options:SAMEORIGIN');
	
global $mysqli;

	if(($mysqli=mysqli_connect("localhost","root",""))==null) //root和后面为空的那个分别是数据库的用户名和密码,使用时要按照你的数据库来修改
	    die('Could not connect: ' . mysqli_error($mysqli));//连接不上数据库
	// use db
	mysqli_query($mysqli,"set names utf8");
  //if(!$OJ_SAE)mysqli_set_charset("utf8");
	
	if(!mysqli_select_db($mysqli,"student")) //student是你要使用的数据库的名字,使用时也要按自己的修改
		die('Can\'t use foo : ' . mysqli_error($mysqli));//找不到名为student的库

	//sychronize php and mysql server with timezone settings, dafault setting for China
	//if you are not from China, comment out these two lines or modify them.
	date_default_timezone_set("PRC");
	mysqli_query($mysqli,"SET time_zone ='+8:00'");
?>

首页:(有很多美化界面的语句)


<!doctpye html>
<html lang ="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">  
    
     <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
     <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
 
    <title>学生公寓管理</title>
    <style type="text/css">
//    body {background-image:url(/a.jpg);}
    p.dashed {border-style: dashed}
    </style>
    
  </head>


<center>
    <body>
        <div class='container'>
    <hr>
    <h1 style="font-family:verdana;opacity:0.5;background-color:#F4A460;color:red"><p class="dashed">学生公寓管理</p></h1>
    <a class='btn btn-info' aria-hidden="true" href="tile.php"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>刷新</a>
    <a class='btn btn-warning' href="add.php"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加</a>
    <a class='btn btn-primary' href="search.php"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</a>  
    <hr>
    
    
    <table class='table table-striped'>
        <tr>
            <th width="100">宿舍号</th>
            <th width="150">学生人数</th>
            <th width="100">宿舍长</th>
            <th width="150">联系方式</th>
            <th width="100">水电费(元)</th>
            <th width="150">卫生检查</th>
            <th width="100">操作</th>
        </tr>
        <?php
            require_once("mysql_conn.php");//导入数据库
            
            $sql = "select * from stu_info";
            
            $result = mysqli_query($mysqli,$sql);
   
            
            if($result && mysqli_num_rows($result) > 0){
                while($rows = mysqli_fetch_array($result)){
                    echo '<tr>';
                        echo '<td width="100">'.$rows['id'].'</td>';
                        echo '<td width="150">'.$rows['num'].'</td>';
                        echo '<td width="100">'.$rows['name'].'</td>';
                        echo '<td width="150">'.$rows['phone'].'</td>';
                        echo '<td width="100">'.$rows['mom'].'</td>';
                        echo '<td width="150">'.$rows['Flag'].'</td>';
                        echo '<td width="100">';
                            echo '<a href="edit.php?id='.$rows['id'].'">编辑</a>';
                            echo ' <a href="delete.php?id='.$rows['id'].'">删除</a>';
                        echo '</td>';
                    echo '</tr>';
                }
            }
            else{
                echo '读取失败...</br>';
            }
            
        ?>

    </table>
    
</center>

    </div>


</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值