<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/memberpage.css">
<link rel="stylesheet" href="css/formular.css">
<meta charset="utf-8">
<title>Snapfinder - Startseite</title>
</head>
<?php
require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); exit(); }
//define page title
$title = 'Snapfinder - Startseite';
//include header template
require('layout/headermember.php');
?>
<br>
<br>
<?php
echo "<body style=\"background-color: #2F4F4F; \">";
?>
<!-- Wilkommens Nachricht -->
<br
<div class="container2">
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<h2> Hey <?php echo htmlspecialchars($_SESSION['username'], ENT_QUOTES); ?>!</h2>
<h2> Nach welchen Nutzer suchst du? </h2>
<!-- Trenn Strich -->
<hr>
<style>
h2 {
color: #F9F6F6;
}
body {
font-family: Verdana, Sans-Serif;
font-size: 1rem;
}
form {
color: #000000;
width: 410px;
padding: 10px;
margin: Auto;
}
.ftext {
color: #000000;
}
.wtext {
color: black;
}
</style>
<body>
<h1>Nach Users suchen</h1>
<form action="memberpage.php" method="post">
<table border="1" cellpadding="20">
<tr>
<td>
<h2>Alter</h2>
<p>von <input name="alterMin"> bis <input name="alterMax"> €</p>
</td>
</tr>
<tr>
<td>
<h2>Bundesland:</h2>
<p>
<select name="bundesland">
<option value="alle">Alle</option>
<option value="1">Baden-Württemberg</option>
<option value="2">Bayern</option>
<option value="3">Berlin</option>
<option value="4">Brandenburg</option>
<option value="5">Bremen</option>
<option value="6">Hamburg</option>
<option value="7">Hessen</option>
<option value="8">Mecklenburg-Vorpommern</option>
<option value="9">Niedersachsen</option>
<option value="10">Nordrhein-Westfalen</option>
<option value="11">Rheinland-Pfalz</option>
<option value="12">Saarland</option>
<option value="13">Sachsen</option>
<option value="14">Sachsen-Anhalt</option>
<option value="15">Schleswig-Holstein</option>
<option value="16">Thüringen</option>
</select>
</p>
</td>
<td>
<h2>Geschlecht:</h2>
<p>
<input type="radio" name="geschlecht" value="M" checked="checked"> Männlich<br>
<input type="radio" name="geschlecht" value="W" > Weiblich<br>
</p>
</td>
</tr>
<td>
<h2>Mit Profilbild?:</h2>
<p>
<input type="radio" name="avatarID" value="1" checked="checked"> Ja<br>
<input type="radio" name="avatarID" value="2" > Nein<br>
</p>
</td>
</tr>
</table>
<input style="margin-top: 25px" type="submit" value="Suche starten">
</form>
</body>
</html>
<?php
//Mit MySQL-Datenbank verbinden
$host_name = 'localhost';
$user_name = 'root';
$password = '';
$database = 'db';
$connect = mysqli_connect($host_name, $user_name, $password, $database);
$abfrage ="SELECT * FROM `members` WHERE nr > 0";
// Suche nach Alter
$alterMin = 16;
$alterMax = 100;
if ( isset($_POST["alterMin"]) ) {
echo $_POST["alterMin"];
$alterMin = $_POST["alterMin"];
$abfrage .= " AND alter > $alterMin";
}
if ( isset($_POST["alterMin"]) ) {
echo $_POST["alterMax"];
$alterMax = $_POST["alterMax"];
$abfrage .= " AND alter < $alterMax";
}
//Suche nach bundesland
$Min = 0;
$Max = 16;
switch (isset ($_POST["bundesland"])){;
case "alle": //tu nichts
break; //verlassen
case "Baden-Württemberg":
$Min = 1;
$Max = 1;
break;
case "Bayern":
$Min = 2;
$Max = 2;
break;
case "Berlin":
$Min = 3;
$Max = 3;
break;
case "Brandenburg":
$Min = 4;
$Max = 4;
break;
case "Bremen":
$Min = 5;
$Max = 5;
break;
case "Hamburg":
$Min = 6;
$Max = 6;
break;
case "Hessen":
$Min = 7;
$Max = 7;
break;
case "Mecklenburg-Vorpommern":
$Min = 8;
$Max = 8;
break;
case "Niedersachsen":
$Min = 9;
$Max = 9;
break;
case "Nordrhein-Westfalen":
$Min = 10;
$Max = 10;
break;
case "Rheinland-Pfalz":
$Min = 11;
$Max = 11;
break;
case "Saarland":
$Min = 12;
$Max = 12;
break;
case "Sachsen":
$Min = 13;
$Max = 13;
break;
case "Sachsen-Anhalt":
$Min = 14;
$Max = 14;
break;
case "Schleswig-Holstein":
$Min = 15;
$Max = 15;
break;
case "Thüringen":
$Min = 16;
$Nax = 16;
break;
}
$abfrage .= " AND bundesland > $Min AND bundesland < $Max";
//Suche nach Geschlecht
if ( isset($_POST["geschlecht"]) ) {
echo $_POST["geschlecht"] == "M";
$abfrage .= " AND geschlecht = M";
}
if ( isset($_POST["geschlecht"]) ) {
echo $_POST["geschlecht"] == "W";
$abfrage .= " AND geschlecht = W";
}
if ( isset($_POST["avatarID"]) ) {
echo $_POST["avatarID"] == "1";
$abfrage .= " AND avatarID = 1";
}
if ( isset($_POST["avatarID"]) ) {
echo $_POST["avatarID"] == "2";
$abfrage .= " AND avatarID = 2";
}
//Abfrage zu Testzwecken am Bildschirm ausgeben
//echo $abfrage;
//SQL-Abfrage ausführen
$result = mysqli_query($connect, $abfrage);
//Ergebnis am Bildschirm ausgeben
echo "<h1>Users:</h1>
<table border='1'><th>Alter</th><th>Bundesland</th><th>Geschlecht</th><th>Profilbild</th>";
while ($dsatz = $result->fetch_assoc()){
echo "<tr>
<td>" . $dsatz["alter"] . "</td>
<td>" . $dsatz["bundesland"] . "</td>
<td>" . $dsatz["geschlecht"] . "</td>
<td>" . $dsatz["profilbild"] . "</td>
</tr>";
}
echo "</table>";
// Verbindung trennen:
mysqli_close($connect);
?>
<?php
//include header template
require('layout/footer.php');
?>
您好社区,我的网站有问题 我想编写一个可以用不同条件设置的搜索。
但不幸的是,我得到了此错误代码,谷歌我没有找到任何可以进一步帮助我的东西
我是PHP的初学者,为我的英语不好而道歉
也许可以帮助我,谢谢 错误代码 致命错误:未捕获错误:在C:\ xampp \ htdocs \ memberpage.php:242中的bool上调用成员函数fetch_assoc()堆栈跟踪:#0 {main}在C:\ xampp \ htdocs \ memberpage.php中抛出242行
搜索也没有我不理解的功能 只是行不通,我不知道还有什么我希望你能帮助我..谢谢!