我想從我的數據庫中的關係表中調用書的詳細信息,mysql是用代碼的語法拋出一個錯誤。前一頁是mysql不喜歡我的聲明
<html>
<head>
<title>Retrieve Relationships</title>
</head>
<body>
<dl>
<?php
// Connect to database server
mysql_connect("localhost","","") or die (mysql_error());
// Select database
mysql_select_db("test") or die(mysql_error());
// Get data from the database depending on the value of the id in the URL
$title = (isset($_GET['title']) && is_string($_GET['title'])) ? $_GET['title'] : null;
$sTitle = mysql_real_escape_string($title);
$strSQL = "SELECT relationships.bookone, relationships.booktwo, relationships.relationship
FROM relationships, books
WHERE books.bookid=relationships.bookone AND relationships.bookone='{$sTitle}'";
$rs = mysql_query($strSQL)
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)){
// Write the data of the person
echo "<dt>Book One:</dt><dd>" . $row["bookone"] . "</dd>";
echo "<dt>Book Two:</dt><dd>" . $row["booktwo"] . "</dd>";
echo "<dt>Relationship:</dt><dd>" . $row["relationship"] . "</dd>";
echo "<dt>Likes:</dt><dd>" . $row["relationshiplikes"] . "</dd>";
echo "<dt>Dislikes:</dt><dd>" . $row["relationshipdislikes"] . "</dd>";
}
// Close the database connection
mysql_close();
?>
</dl>
<p><a href="search.php">Return to the list</a></p>
</body>
</html>
什麼即時試圖去顯示的頁面是bookone的代碼和booktwo的代碼,其中bookones ID = booksid
任何幫助,將不勝感激
更改到'$ RS =請求mysql_query($ STRSQL)或死亡(mysql_error());',看看它說: –
你把到查詢變量如果它是一個字符串,則需要使用單引號。此外,您的代碼已經開放給SQL注入。 – Corbin
你沒有在你的查詢中關閉這個單引號:''{$ sTitle}' – Okonomiyaki3000