我为一个学校项目制作了这个网站,它似乎没有检索数据。我一直在检查它 AGES 并且无法找出它为什么不检索。SQL 有时在 phpMyAdmin 中有效,但在界面中从不有效。
<?php
$con=mysqli_connect("localhost","root","#","book_catalogue");
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<div id="wrapper">
<div id="left-col">
<img src="images/left-img.png" alt="books" />
</div>
<div id="header">
<h1>BOOK CATALOGUE</h1>
</div>
<!--Radio buttons that allow user to select the search criteria-->
<div id="navigation">
<form name="input" action="indexV4.php" method="get">
SEARCH BY: ALL<input type="radio" name="books" value="ALL" checked>
TITLE<input type="radio" name="books" value="TITLE">
AUTHOR<input type="radio" name="books" value="AUTHOR">
GENRE<input type="radio" name="books" value="GENRE">
BOOK TYPE<input type="radio" name="books" value="BOOKTYPE">
<input type="text" name="SEARCH" value="SEARCH">
<input type="submit" value="GO">
</form>
</div>
<?php
$Books = $_GET['books'];
$Search = $_GET['SEARCH'];
//if the radio button 'TITLE' is selected, this query will run
if($Books=='TITLE')
{
$result = mysqli_query($con,"
SELECT tbl_books.ISBN, tbl_books.Title, tbl_books.Author, tbl_books.Book_Image, tbl_book_type.Name, tbl_categories.Name FROM tbl_books, tbl_book_type, tbl_categories WHERE (tbl_books.Type_id = tbl_book_type.Type_id) AND (tbl_books.Category_id = tbl_categories.Category_id)
WHERE tbl_books.Title LIKE '%$Search%'");
}
//if the radio button 'AUTHOR' is selected, this query will run
else if ($Books=='AUTHOR')
{
$result = mysqli_query($con,"
SELECT tbl_books.ISBN, tbl_books.Title, tbl_books.Author, tbl_books.Book_Image, tbl_book_type.Name, tbl_categories.Name FROM tbl_books, tbl_book_type, tbl_categories
WHERE (tbl_books.Type_id = tbl_book_type.Type_id) AND (tbl_books.Category_id = tbl_categories.Category_id)
WHERE tbl_books.Author LIKE '%$Search%'");
}
//if the radio button 'GENRE' is selected, this query will run
else if ($Books=='GENRE')
{
$result = mysqli_query($con,"
SELECT tbl_books.ISBN, tbl_books.Title, tbl_books.Author, tbl_books.Book_Image, tbl_books.Type_id, tbl_books.Category_id FROM tbl_books
WHERE tbl_books.Author LIKE '%$Search%'");
}
//if the radio button 'BOOK TYPE' is selected, this query will run
else if ($Books=='BOOKTYPE')
{
$result = mysqli_query($con,"
SELECT tbl_books.ISBN, tbl_books.Title, tbl_books.Author, tbl_books.Book_Image, tbl_book_type.Name, tbl_categories.Name FROM tbl_books, tbl_book_type, tbl_categories
WHERE (tbl_books.Type_id = tbl_book_type.Type_id) AND (tbl_books.Category_id = tbl_categories.Category_id)
WHERE tbl_book_type.Name LIKE '%$Search%'");
}
//if 'ALL' is selected, this query will run
else
{
$result = mysqli_query($con, "
SELECT tbl_books.ISBN, tbl_books.Title, tbl_book_type.Name, tbl_categories.Name FROM tbl_books, tbl_book_type, tbl_categories WHERE (tbl_books.Type_id = tbl_book_type.Type_id) AND (tbl_books.Category_id = tbl_categories.Category_id)
WHERE tbl_books.Title OR tbl_books.Author OR tbl_categories.Name OR tbl_book_type.Name LIKE '%$Search%'");
}
//while it is retrieving the data, echo it onto the screen
while($row = mysqli_fetch_array($result,MYSQLI_BOTH))
{
?>
</div>
<div id="content">
<!--Display of search results-->
<div class="books">
<img src="book-covers/<?php echo $row['Book_Image']; ?>" alt="<?php echo $row['Title']; ?>" />
<p class="first"><?php echo $row['Title']; ?></p>
<p><?php echo $row['Author']; ?></p>
<p><?php echo $row['ISBN']; ?></p>
<p><?php echo $row['Type_id']; ?></p>
<p><?php echo $row['Category_id']; ?></p>
</div>
</div>
<?php
//close the loop
}
?>
</div>