问题遇到的现象和发生背景
用PHP写了一个从数据库查询并显示结果的功能,但无法利用POST得到搜索框输入的内容
这是搜索框↓
查询结果页面↓
三个搜索框都是传参失败不知道为什么
用代码块功能插入代码
//因为三个搜索框都是一个套路,这里只放主界面和第一个搜索框的内容了
<!DOCTYPE html>//主页面代码
<html>
<head>
<title>主页</title>
<link rel="stylesheet" href="main.css">
<meta charset="UTF-8">
</head>
<body>
<div id="kuangjia" style="width:1200px">
<div id="header" style="background-color:#99d6ea80;text-align:center">⚠本站结果仅供参考,若有不适请您及时就医⚠</div>
<div id="serchsym" style="background-color:#99d6ea25;height:300px;width:400px;float:left">
<form action="serchactone.php" method="post">
<div id="inputbox">
<p>症状查询<input type="text" class="text" id ="serchsym" name="serchsym" style="height:30px;width:210px" placeholder="请输入症状,可以少但不可以多"></p>
<p1><input onclick="{location.href='serchactone.php'}" type="button" class="btn" value="查询"></p1>
</div>
</form>
</div>
</div>
</div>
<div id="searchmed" style="background-color:#99d6ea35;height:300px;width:400px;float:left">
<form action="serchacttwo.php" method="post">
<div id="inputbox">
<p>药品查询<input type="text" class="text" name="serachmed" style="height:30px;width:210px" placeholder="请输入药品名称"></p>
<p1><input onclick="{location.href='serchacttwo.php'}" type="button" class="btn" value="查询"></p1>
</div>
</form>
</div>
<div id="searchctm" style="background-color:#99d6ea25;height:300px;width:400px;float:left">
<div id="inputbox">
<p>中药查询<input type="text" class="text" name="serachthree" style="height:30px;width:210px" placeholder="请输入中药名称,不要错字哦"></p>
<p1><input onclick="{location.href='answerthree.php'}" type="button" class="btn" value="查询"></p1>
<input onclick="window.location.href='https://ai.baidu.com/tech/imagerecognition/plant'" type="button" class="btn" value="拍照查询">
</div>
</div>
<div id="footer" style="background-color:#99d6ea80;clear:both;text-align:center">⚠本站结果仅供参考,若有不适请您及时就医⚠</div>
</div>
</body>
</html>
<!DOCTYPE html>//第一个搜索框跳转界面代码
<html>
<head>
<title>查询结果</title>
<meta charset="UTF-8">
</head>
<body>
<div id="kuangjia" style="width:1200px">
<div id="header" style="background-color:#99d6ea80;text-align:center">查询结果</div>
<?php
$conn = mysqli_connect("localhost", "root", "123456") or die("数据库链接错误");
$db_selected=mysqli_select_db($conn,"SafeAskM");
$serchsym = isset($_POST['serchsym']) ? $_POST['serchsym']:'';
if(!empty($serchsym)) {
$sql = "SELECT disease,symptom,pathogeny,medicine FROM ask_s WHERE symptom LIKE '%$serchsym%'";
$query = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($query)) {
$valuea = '';
foreach($row as $valuea){
echo $valuea;
}
}
}else{
echo"啊哦,页面不见了哦";
}
?>
<div id="footer" style="background-color:#99d6ea80;clear:both;text-align:center">⚠本站结果仅供参考,若有不适请您及时就医⚠</div>
</div>
</body>
</html>
我的解答思路和尝试过的方法
之前做测试的时候是能成功搜索的,在我更改了一下链接的数据库以后就不行了,所以想问问是我的代码有问题还是数据库有问题