Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当有撇号时,搜索不起作用_Php_Html_Mysql_Workbench - Fatal编程技术网

Php 当有撇号时,搜索不起作用

Php 当有撇号时,搜索不起作用,php,html,mysql,workbench,Php,Html,Mysql,Workbench,我正在尝试建立一个OPAC网站。一切正常,因为它主要只是从数据库中选择并显示它。我注意到,当我试图搜索的书名有一个撇号时,它什么也不显示。如果书名中没有任何撇号,那么一切都可以。我正在使用mysql作为我的数据库 <!-- {this is how i connect my datatbase} --> <?php include 'includes/dbh.inc.php'; ?> <!DOCTYPE <!DOCTYPE html> <html

我正在尝试建立一个OPAC网站。一切正常,因为它主要只是从数据库中选择并显示它。我注意到,当我试图搜索的书名有一个撇号时,它什么也不显示。如果书名中没有任何撇号,那么一切都可以。我正在使用mysql作为我的数据库

<!-- {this is how i connect my datatbase} -->
<?php
include 'includes/dbh.inc.php';
?>

<!DOCTYPE <!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>

<div id= "wrapper">
<a href = "index.php"><img class="cpclogo" src="cpc.png"></a>
<header>
    <h1 class="CPC"> Colegio de la Purisima Concepcion </h1>
    <h3 class="Saying"> The School of the Archdiocese of Capiz </h3>
</header>
</div>
header.php文件

<?php

$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "library";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>
search.php文件

<?php
    include 'header.php'
?>

<h1 class="searchresults">Search Results:</h1>

<div class="search-container">
    <?php
    if (isset($_POST['submit']))
    {
        $search = mysqli_real_escape_string($conn, $_POST['search']);
        $sql = "SELECT * FROM book WHERE Book_Title LIKE '%$search%' OR Author LIKE '%$search%' OR Call_Number LIKE '%$search%' OR Book_ID LIKE '%$search%'";
        $result = mysqli_query($conn, $sql);
        $queryResult = mysqli_num_rows($result);
        $search = mysqli_real_escape_string($conn, $_POST['search']);

        echo "<h3 class='resultcount'>There are ".$queryResult." results!</h3>";

        if ($queryResult > 0)
        {
            while ($row = mysqli_fetch_assoc($result))
            {
                echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>
                <tr><td>".$row['Book_Title']." </td>
                <td>/ ".$row['Author']."</td>
                <p>".$row['Call_Number']."</p>
                </div></tr><br>";
            }

        }
    }
    ?>
    <input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
</div>
article.php文件

<?php
    include 'header.php';
?>

<div class="article-container">

<?php
//Declairing Variables
$Author = "Authors: ";
$Edition = "Edition: ";
$Subject ="Subject: ";
$Summary = "Summary: ";
$Notes = "Notes: ";
$Publisher ="Publisher: ";
$Phys_Desc ="Physical Description: ";
$Call_Number ="Call Number: ";
$Book_ID = "Book ID: ";


$Title= mysqli_real_escape_string($conn, $_GET['Book_Title']);

$sql ="SELECT * FROM book WHERE Book_Title='$Title'";
$result = mysqli_query($conn, $sql);      
$queryResult = mysqli_num_rows($result);

if ($queryResult > 0)
while ($row = mysqli_fetch_assoc($result))
{
echo "<div class= 'article-box'>
    <h3 class='booktitle'><b>".$row['Book_Title']."</h3></b>
    <p><b>$Author</b>".$row['Author']."</p>
    <p><b>$Edition</b>".$row['Edition']."</p>
    <p><b>$Subject</b>".$row['Subject']."</p>
    <p><b>$Summary</b>".$row['Summary']."</p>
    <p><b>$Notes</b>".$row['Notes']."</p>
    <p><b>$Publisher</b>".$row['Publisher']."</p>
    <p><b>$Phys_Desc</b>".$row['Phys_Desc']."</p>
    <p><b>$Call_Number</b>".$row['Call_Number']."</p>
</div>";
}
?>
<div class="btns">
    <input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
    <button type="submit" id="copybtn" class= "copybtn">Copies</button>
</div>


<!-- POP-UP WINDOW -->
<div class="bg-modal">
    <div class="modal-content">
    <div class="close"></div>
        <table class = "table">
    <tr>
        <th>Copy</th>
        <th>Status</th>
        <th>Accession Number</th>
        <th>Call Number</th>
        <th>Location</th>
        <th>Format</th>
        <th>Cost</th>
        <th>Vendor</th>
        <th>Fund</th>
        <th>Date Acquired</th>
    </tr>
    <?php

    $id = mysqli_real_escape_string($conn, $_GET['id']);
    $call = mysqli_real_escape_string($conn, $_GET['call']);

    $sql = "SELECT Copy, Status, Accession_Number, l.Location, f.Format, Cost, Vendor, u.Fund, Date_Acq
    FROM copy c
    INNER JOIN location l ON l.Location_Acronym = c.Location
    INNER JOIN format f ON f.Format_ID = c.Format
    INNER JOIN fund u ON u.Fund_ID = c.Fund
    WHERE Book_ID='$id'";

    $result = mysqli_query($conn, $sql);
    $queryResult = mysqli_num_rows($result);

    if ($queryResult > 0)
    {
      while ($row = mysqli_fetch_assoc($result))
      {

        echo "
        <tr><td>".$row['Copy']."</td>
        <td>".$row['Status']."</td>
        <td>".$row['Accession_Number']."</td>
        <td>".$call."</td>
        <td>".$row['Location']."</td>
        <td>".$row['Format']."</td>
        <td>₱".$row['Cost']."</td>
        <td>".$row['Vendor']."</td>
        <td>".$row['Fund']."</td>
        <td>".$row['Date_Acq']."</td></tr>
        ";
      }

    }
  ?>

 </table>
    </div>
</div>
<script src="popup.js"></script>
</body>
</html>
复制.php文件

<?php
    include 'header.php'
?>

<h1 class="copyresults">Copy Results:</h1>

<div class="article-container">

<table class = "table">
    <tr>
        <th>Barcode</th>
        <th>Copy</th>
        <th>Status</th>
        <th>Location</th>
        <th>Format</th>
        <th>Vendor</th>
    </tr>
    <?php
    {
        $id = mysqli_real_escape_string($conn, $_GET['id']);

        $sql = "SELECT * FROM copy WHERE Book_ID='$id'";
        $result = mysqli_query($conn, $sql);
        $queryResult = mysqli_num_rows($result);

        if ($queryResult > 0)
        {
            while ($row = mysqli_fetch_assoc($result))
            {

                echo "
                <tr><td>".$row['Barcode']."</td>
                <td>".$row['Copy']."</td>
                <td>".$row['Status']."</td>
                <td>".$row['Location']."</td>
                <td>".$row['Format']."</td>
                <td>".$row['Vendor']."</td></tr>
                ";
            }

        }

    }
    ?>
    </table>

我认为这有点可疑:

echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>...
或者这可能会使您的代码更具吸引力,当然也更健壮:

$data = [
    'Book_Title' => $row['Book_Title'],
    'id' => $row['Book_ID'],
    'call' => $row['Call_Number']
];
echo "<a href='article.php?" . http_build_query($data) . "' class='search-ref'><div class=search-box>...

-永远不要执行此操作:从书中选择*,书名为“%$search%”或作者为“%$search%”,或调用书号为“%$search%”或书号为“%$search%”,您尝试查找错误的原因是什么?您是否检查过MySQL是否向您报告任何内容?此外,您有一些没有表元素的表行和单元格元素。你需要把你的分数整理一下。非常感谢!urlencode解决了这个问题。非常感谢你的帮助我的荣幸。今后,请尽量将您的问题隔离一点,以便对未来的研究人员和志愿者更具吸引力。随着时间的推移,我们在这个社区的发帖能力都有所提高。快乐编码。
$data = [
    'Book_Title' => $row['Book_Title'],
    'id' => $row['Book_ID'],
    'call' => $row['Call_Number']
];
echo "<a href='article.php?" . http_build_query($data) . "' class='search-ref'><div class=search-box>...