php第四次作业

<?php
header("Content-type: text/html; charset=utf-8");
$serviceHost = "localhost";
$username = "root";
$password = "root";
$database = "vrs";
$target = $_GET['serchForm'] ? $_GET['serchForm'] :'';
@$conn = mysqli_connect($serviceHost, $username, $password, $database);
if (!$conn) {
    die("Connection failed6666: " . mysqli_connect_error());
}
mysqli_set_charset($conn, "utf8");
$sqlCode = "SELECT * FROM vol_info";
if ($target){
    $sqlCode = $sqlCode." where name like '%$target%'";
}
$result = mysqli_query($conn, $sqlCode);
$fetch = mysqli_fetch_all($result);

include_once "index.php";

mysqli_free_result($result);
mysqli_close($conn);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <form action="aservice.php">
        <input name="serchForm">
        <button type="submit">serch</button>
    </form>
</div>
<div>
    <h1>学生党员消息</h1>
    <table>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>org</th>
            <th>birth</th>
            <th>reg_time</th>
        </tr>
        <?php

        foreach($fetch as $row){
            ?>
            <tr>
                <td><?=$row[0]?></td>
                <td><?= $row[1] ?></td>
                <td><?=$row[2]?></td>
                <td><?=$row[3]?></td>
                <td><?=$row[4]?></td>
            </tr>

        <?php } ?>

    </table>
</div>
</body>
</html>

第一段为连接数据库代码

第二段为前端代码起名为index.php(因为第一段代码用这个名字将前端项目导入后端)

注意修改自己的数据库密码!!!!!!!!!!!!!!!!!($password)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值