<?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)

被折叠的 条评论
为什么被折叠?



