我正在使用site人们可以过滤搜索结果。当我点击提交按钮时,表单似乎没有发送项目。请指导。感谢。
<form action="search.php" method="get" >
City:<br>
<input id="city" value="">
<hr>
<!--
Area:<br>
<input id="area" placeholder="Select Area">
<hr>
-->
Gender:<br>
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female<br>
<hr>
<!--
<p>
Age range:<br>
<input type="text" id="amount"/>
</p>
<div id="slider-range"></div>
<hr>
-->
School:<br>
<input id="school" >
<hr>
College:<br>
<input id="college">
<hr>
University:<br>
<input id="university">
<hr>
<button type="submit" class="btn btn-success btn-lg">Search</button>
</form>
MySQL的:
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$city = $_GET["city"];
$gender = $_GET["gender"];
$school = $_GET["school"];
$college = $_GET["college"];
$university = $_GET["university"];
// $sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users WHERE city='$city' and gender='$gender' and school='$school' and college='$college' and university='$university'";
if(!empty ($city) and empty($gender) and empty ($school) and empty ($college) and empty ($university) )
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where city='$city' ";
elseif(!empty ($gender) and empty($city) and empty ($school) and empty ($college) and empty ($university) )
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where gender='$gender' ";
elseif(!empty ($school) and empty($city) and ($gender) and empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where school='$school' ";
echo "229";
}
elseif(!empty ($college) and empty($city) and empty ($school) and empty ($gender) and empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where college='$college' ";
echo "233";
}
elseif(!empty ($university) and empty ($city) and empty ($school) and empty ($gender)and empty ($college) and empty ($college) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where university='$university' ";
echo "227";
}
elseif(!empty ($city) and !empty($gender) and empty ($school) and empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where city='$city' and gender='$gender'";
echo "227";
}
elseif(!empty ($city) and empty($gender) and !empty ($school) and empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where city='$city' and school='$school'";
echo "242";
}
elseif(!empty ($city) and empty($gender) and empty ($school) and !empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where city='$city' and college='$college'";
echo "245";
}
elseif(!empty ($city) and empty($gender) and empty ($school) and empty ($college) and !empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where city='$city' and university='$university'";
echo "248";
}
elseif(empty ($city) and !empty($gender) and !empty ($school) and empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where gender='$gender' and school='$school'";
echo "251";
}
elseif(empty ($city) and !empty($gender) and empty ($school) and !empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where gender='$gender' and college='$college'";
echo "254";
}
elseif(empty ($city) and !empty($gender) and empty ($school) and empty ($college) and !empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where gender='$gender' and university='$university'";
echo "257";
}
elseif(empty ($city) and empty($gender) and !empty ($school) and !empty ($college) and empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where school='$school' and college='$college'";
echo "260";
}
elseif(empty ($city) and empty($gender) and !empty ($school) and empty ($college) and !empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where school='$school' and university='$university'";
echo "263";
}
elseif(empty ($city) and empty($gender) and empty ($school) and !empty ($college) and !empty ($university) ){
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where college='$college' and university='$university'";
echo "279";
}
/*
if($city and $gender)
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users where";
*/
else{
$sql = "SELECT id,full_name, email, password,area,city,age,contact_number,gender,school,college,university FROM users";
echo "295";
}
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Name:" . $row["full_name"]."<br> Email:". $row["email"]. "<br>City: " . $row["city"]. "<br>Age: " . $row["age"]. "<br>Contact Number:". $row["contact_number"]. "<br> Gender: " . $row["gender"]. "<br>School:" . $row["school"]. "<br> College:". $row["college"]."<br>University:" . $row["university"];
echo "<br><hr>";
}
} else {
echo "0 results";
}
$conn->close();
?>
答案 0 :(得分:1)
您的输入字段缺少type
和name
属性。试试这个:
<form action="search.php" method="get" >
City:<br>
<input type="text" name="city" value="">
<hr>
<!--
Area:<br>
<input type="text" name="area" placeholder="Select Area">
<hr>
-->
Gender:<br>
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female<br>
<hr>
<!--
<p>
Age range:<br>
<input type="text" name="amount"/>
</p>
<div id="slider-range"></div>
<hr>
-->
School:<br>
<input type="text" name="school" >
<hr>
College:<br>
<input type="text" name="college">
<hr>
University:<br>
<input type="text" name="university">
<hr>
<button type="submit" class="btn btn-success btn-lg">Search</button>
</form>