为什么我不能搜索我的项目数据库? - 各种警告

时间:2017-06-10 00:09:05

标签: php mysql database

我可以先说我正在做一个计算课程,其中一个单元是介绍PHP并且我刚刚开始进入PHP。

此时我非常基本,我的任务是建立一个搜索页面,可以搜索不同的电影等。

我的生产页面(搜索页面)

 <!DOCTYPE html>
<html>
<head>

<title>Royal Theatre</title>    
<link rel="stylesheet" href="css/main.css">
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">

</head>
<body> 

    <header>

        <img src="image/logo2.png">
    </header>

    <div class="nav">
  <ul>
    <li class="home"><a href="index.php">Home</a></li>
    <li class="Production"><a class="active" 
href="production.php">Production</a></li>
    <li class="Contact"><a href="contact.php">Contact</a></li>
  </ul>
</div>


<h1>Search For Shows</h1>
<form action="presults.php" method="GET">
<br>
<label for="name" class="pd">Production Name:</label>
<br>
<input type="text" name="name">
<br>
<label for="genre" class="gnr">Genre:</label>
<br>
<input type="text" name="genre">
<br>
<label for="date" class="dte">Date:</label>
<br>
<input type="date" name="date">
<br>
<label for="time" class="tme">Starting Time:</label>
<br>
<input type="date_list" name="time">



    <datalist id="production">


    <option value="Little Stars: Dance">
        <option value="RSNO Community Orchestra">
            <option value="Nicki Minaj">
                <option value="Harlem Globetrotters">
                    <option value="Alan Davies">
                        <option value="WWE">
                            <option value="Amazon Echo and the singing AI">
                                <option value="Spirited Away The Play">
                                    <option value="A Generic Stand Up Comedy 
Act">
                                        <option value="My Life Is A Joke">
                                            <option value="Rangers Football 
  Club">
                                                <option value="NEDs">
                                                    <option value="NZXT & 
The CAM Software">
                                                        <option 
value="Franky Boil Tribute Act">
                                                            <option 
value="Wee Archie & The Akitas">
  </datalist>
  <input type="submit" name="submit" value="Search" />




    </form>


    <table>
        <?php

        echo "<TR><th>Production Reference</th> <th>Production Name</th> 
<th>Genre</th> <th>Date</th> <th>Starting Time</th> <th>Price Band</th>";

    while ($row = mysqli_fetch_array($result)){
            $reference=$row['reference'];
            $name=$row['name'];
            $genre=$row['genre'];
            $date=$row['date'];
            $time=$row['time'];
            $pband=$row['pband'];
    ?>
            <tr>
                <td>
                    <?php echo "$reference";?>
                </td>
                <td>
                    <?php echo "$name";?>
                </td>
                <td>
                    <?php echo "$genre";?>
                </td>
                <td>
                    <?php echo "$date";?>
                </td>
                <td>
                    <?php echo "$time";?>
                </td>
                <td>
                    <?php echo "$pband";?>
                </td>
            </tr>
            <?php }?>
    </table>






      <footer>
 © Scott
</footer>

</body>   
</html>

我的结果php

<?php

if(!isset($_GET['submit'])){

header('Location: production.php');
}else{

$name = $_GET['name'];
$genre = $_GET['genre'];
$time = $_GET['time'];
$date = $_GET['date'];


include'connection.php';

$query = "SELECT production.name, production.genre, production.date, production.time, price.adult, price.child, price.concession, price.pband FROM production, price WHERE production.name = '$name' AND production.genre = '$genre' AND production.date = '$date' AND production.time = '$time' AND production.pband = price.pband";


$result = mysqli_query($con, $query);

?>



<!Doctype HTML>
<html>

<head>
<meta charset="utf-8">
<title>Production Results</title>
<link rel="stylesheet" type="text/css" href="main.css"> </head>

<body>

<h1>Search Result</h1>

<table>




<th class="TH">Production Reference</th>
  <th class="TH">Production Name</th>
  <th class="TH">Genre</th>
  <th class="TH">Date</th>
  <th class="TH">Starting Time</th>
  <th class="TH">Price Band</th>

 <?php

if(mysqli_num_rows($result) == 0){echo"<tr> <td class='TD'>" . 'No Results 
Found' . "</td></tr>";}

    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

 $date = $row['date'];
 $date = strtotime($date);
 $date = date('d-M-Y', $date);

       echo"<td class='TD'><a href='production.php'>Back to the main search 
page</a></td>";
echo "</table>"; 
    echo "<tr>


    <td class='TD'>" . $row['reference'] . "</td>
       <td class='TD'>" . $row['name'] . "</td>
       <td class='TD'>" . $row['genre'] . "</td>
       <td class='TD'>" . $row['date'] . "</td>
        <td class='TD'>" . $row['time'] . "</td>
       <td class='TD'>" . $row['pband'] . '" /> '. "</td>
     </tr>";

    }
echo"</table>";




}
?>

我的connection.php

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'theatre';

$con = mysqli_connect($host, $user, "",$db);

if(!$con){

die("Connection Failed " . mysqli_connect_error()); 
}else{
echo "";
}
?>

我在搜索&#34; WWE

时遇到的错误

Error

任何帮助都非常感谢,我已经连续几个小时都在这里,并且无法看到问题所在。

非常感谢!

1 个答案:

答案 0 :(得分:0)

这不是答案!

尝试此查询

$query = "SELECT name, genre, date, time, adult, child, concession, pr.pband FROM production p INNER JOIN price pr ON p.pband = pr.pband WHERE name LIKE '$name'";

myresult.php

中的错误

您有错误。在您的connection.php中,您已将$con定义为连接变量,但在查询中使用了$connection

应该是

$result = mysqli_query($con, $query);

connection.php

中的警告

你只需要传递变量,不要将它们放在任何东西中。它应该是

$con = mysqli_connect($host, $user, "",$db);

尝试使用查询

$query = "SELECT reference, name, genre, date, time, pband FROM production p INNER JOIN price pr ON p.pband = pr.pband WHERE name LIKE '$name'";

替换表格的

<td class='TD'>" . $row['reference'] . "</td>
   <td class='TD'>" . $row['name'] . "</td>
   <td class='TD'>" . $row['genre'] . "</td>
   <td class='TD'>" . $row['date'] . "</td>
    <td class='TD'>" . $row['time'] . "</td>
   <td class='TD'>" . $row['pband'] . "</td>
 </tr>";