Ben php ve MySQL ile gerçek bir acemi değilim. Şimdi ben eg veritabanı aramak gerekir aşağıdaki kod üzerinde çalışıyorum. Liverpool yaşayan tüm Lennons.
1) Nasıl metni hiçbir arama sonucu varsa görünmesini "hiçbir sonuç" elde etmek için "get.php" değiştirmek gerekir.
2) nasıl yerine bunları tek tek yazmak zorunda düz veritabanından seçenek değerlerini (şehir ve soyadı) almak için "index.php" değiştirmek gerekir?
3) Ben doğru yolu mysql_real_escape_string kullanıyor muyum?
4) kod Başka hatalar?
index.php:
<form action="get.php" method="post">
<p>
<select name="city">
<option value="Birmingham">Birmingham</option>
<option value="Liverpool">Liverpool</option>
<option value="London">London</option>
</select>
</p>
<p>
<select name="lastname">
<option value="Lennon">Lennon</option>
<option value="McCartney">McCartney</option>
<option value="Osbourne">Osbourne</option>
</select>
</p>
<p>
<input value="Search" type="submit">
</p>
</form>
get.php:
<?php
$city = $_POST['city'];
$lastname = $_POST['lastname'];
$conn = mysql_connect('localhost', 'user', 'password');
mysql_select_db("database", $conn) or die("connection failed");
$query = "SELECT * FROM users WHERE city = '$city' AND lastname = '$lastname'";
$result = mysql_query($query, $conn);
$city = mysql_real_escape_string($_POST['city']);
$lastname = mysql_real_escape_string($_POST['lastname']);
echo $rowcount;
while ($row = mysql_fetch_row($result))
{
if ($rowcount == '0')
echo 'no results';
else
{
echo '<b>City: </b>'.htmlspecialchars($row[0]).'<br />';
echo '<b>Last name: </b>'.htmlspecialchars($row[1]).'<br />';
echo '<b>Information: </b>'.htmlspecialchars($row[2]);
}
}
mysql_close($conn);
?>