我为学校项目制作了一个数据库驱动的网站。 (请记住,我没有遵守版权规则,因为它是一个私人网站 之后会被关闭。
1:我通过名为' verbinding.php'的文件连接了我的数据库。 (我是荷兰人,这将是' connection.php'英文)
<?php
$verbinding = mysqli_connect('localhost','*********','**********','**********');
?>
2:我已经创建了一个文件,我已经编写了数据库和表格。
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<link rel="STYLESHEET" href="dieren.css" type="text/css" />
<title> PO dierentuin </title>
</head>
<?php include 'verbinding.php'
?>
<body>
<div id="zoekvenster">
<p>Zoek door onze database als een varkentje met een heel goed neusje</p>
<form method="post" action="zoeken.php" id="zoekbox">
Zoekwoord <input type="text" name="zoekwoord"><br>
<label><input type="radio" name="categorie" value="animalnumber" id=Cat_1>Diernummer</label><br>
<label><input type="radio" name="categorie" value="species" id=Cat_2>Diersoort</label><br>
<label><input type="radio" name="categorie" value="stay" id=Cat_3>Verblijf</label><br>
<label><input type="radio" name="categorie" value="gender" id=Cat_4>Geslacht</label><br>
<label><input type="radio" name="categorie" value="place of birth" id=Cat_5>Nationaliteit</label><br>
<input type="submit" name="submit" value="Zoeken">
</form>
</div>
<h2>All animals we have</h2>
<div id="inleiding">
<?php
$sqlquery = "SELECT * FROM Dierentuin";
$resultaat = mysqli_query($verbinding, $sqlquery);
$queryResultaat = mysqli_num_rows($resultaat);
echo"
<table border='1'>
<tr>
<th>Animalnumber</th>
<th>Species</th>
<th>Race</th>
<th>Date of birth</th>
<th>Voeding</th>
<th>Stay</th>
<th>Mass</th>
<th>Gender</th>
<th>Place of birth</th>
</tr>";
if ($queryResultaat > 0) {
while ($row = mysqli_fetch_assoc($resultaat)) {
echo "<tr>";
echo "<td>".$row['Diernr']."</td>";
echo "<td>".$row['Soort']."</td>";
echo "<td>".$row['Ras']."</td>";
echo "<td>".$row['Leeftijd']."</td>";
echo "<td>".$row['Voeding']."</td>";
echo "<td>".$row['Verblijf']."</td>";
echo "<td>".$row['Gewicht_in_kg']."</td>";
echo "<td>".$row['M/V']."</td>";
echo "<td>".$row['Nationaliteit']."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "Something went wrong";
}
?>
<br>
<br>
<br>
</div>
<footer>
<p>This assingment was produced by Tieme and Marijn. 5VWO Marne College.</p>
</footer>
</body>
</html>
3:我还有文件&#39; zoeken.php&#39;这将被称为&#39; search.php&#39;因为zoeken是荷兰人的搜索。
<?php
include('verbinding.php');
$zoekwoord = $_POST["zoekwoord"];
$categorie = $_POST["categorie"];
echo $categorie;
echo $zoekwoord;
$query = ("SELECT * FROM dierentuin WHERE $categorie is '$zoekwoord'");
$resultaat = mysqli_query($verbinding, $query);
if ($resultaat > 0) {
while ($row = mysqli_fetch_assoc($resultaat)) {
echo ".'$row'['animalnumber'].";
echo "Het werkt iniedergeval";
}
} else {
echo "Something went wrong";
}
只有当您查看第二个文件中的表单时,您才会注意到有一个文本框和一些无线电。让我们说,我填写刚果&#39;代替出生,并检查radiobox出生地,我应该查看只有在刚果出生的动物的查询。
如果我在我的网站上这样做,无论我填写什么,它都会转到其他地方。在第三个文件中,它说“出了问题&#39;
”有谁知道我做错了什么?
感谢您的支持!
Marijn和Tieme。 (荷兰)
答案 0 :(得分:0)
(&#34; SELECT * FROM dierentuin WHERE $ categorie is&#39; $ zoekwoord&#39;&#34;); 您正在将变量与变量进行比较。
应该是那样的
SELECT * FROM dierentuin WHERE DBfieldname =&#34; $ variable_name&#34;和DBfieldname2 =&#34; $ variable_name2&#34;);