-2

Can I just start off by saying I'm doing a computing course where one of the units is intro to PHP and that I'm JUST starting to get into PHP.

I'm very basic at this point, I have been tasked with making a site with a search page that you can search different movies etc.

My production page (Search Page)

 <!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>

My results 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>";




}
?>

My 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 "";
}
?>

The errors im getting when i search "WWE

Error

Any help at all is really greatly appreciated, I have been at this for hours on end and just can't see what the problem is.

Thanks a lot!

Elydasian
  • 2,016
  • 5
  • 23
  • 41
Balor
  • 3
  • 2
  • 1
    Where is the query? – Ali Rasheed Jun 10 '17 at 00:12
  • @AliRasheed sorry, i messed up the code indentation, its now there. – Balor Jun 10 '17 at 00:18
  • Perhaps your data isn't matching with database row. Search with only name. narrow down your searching criteria. And use `Joins`. – Ali Rasheed Jun 10 '17 at 00:22
  • Every single one of those error messages has been discussed countless times already, and can easily be researched. – CBroe Jun 10 '17 at 00:41
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – CBroe Jun 10 '17 at 00:41
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Qirel Jun 10 '17 at 01:00

1 Answers1

0

THIS IS NOT ANSWER!

Try this query

$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'";

ERROR in myresult.php

You have an error. In your connection.phpyou have defined $con as a connection variable but you used $connection in query.

It should be

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

WARNING in connection.php

you just have to pass variables do not put them in anything.it should be

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

Try using the query

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

Replace HTML of table

<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>";
Ali Rasheed
  • 2,765
  • 2
  • 18
  • 31