0

Im trying to display information from my database that's been fetched by a MySql query. I set this error

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\1\search.php on line 14

Here is the code for search.php

    <?php
if (isset($_POST['searchterm'])){
mysql_connect("localhost","root","Oliver");
mysql_select_db("videos");

$search = mysql_real_escape_string(trim($_POST['searchterm']));

$find_videos = mysql_query("SELECT * FROM `videos` WHERE `keywords` LIKE'%$search%'");
while($row = mysql_fetch_assoc($find_videos))
{
    $name = $row['name'];

    echo "<table">";
  echo "<tr>";
    echo "<td>$name</td>";
  echo "</tr>";
  echo "<tr>";
  echo  "<td>$name</td>";
  echo "</tr>";
echo "</table>";
}
}
?>
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
  <head>
  <link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
  <link rel="icon" type="image/ico" href="images/favicon.ico">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<style type="text/css">
  .vjs-default-skin .vjs-control-bar { font-size: 125% }
</style>
    <meta charset="utf-8">
    <title>Network TV | search</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link href="css/font-awesome.css" rel="stylesheet" />
    <link href="css/3.1.1/animate.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/styles.css" />
  </head>
  <body style="overflow-x: hidden">
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Network TV</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class=""><a href="\1\index.php">Home</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

    <script src="js/scripts.js"></script>
</html>

I already have the form setup to POST the information to this page. When the information is display it's just in a list hanging off the top left side of the screen, i'm trying to display it in a table in the center of the. Here is some examples of things I tried.

echo "<table style=text-align:center">"";
  echo "<tr>";
    echo "<td>$name</td>";
  echo "</tr>";
  echo "<tr>";
  echo  "<td>$name</td>";
  echo "</tr>";
echo "</table>";

This gives me error Parse error: syntax error, unexpected '"<table style="' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\1\search.php on line 13

Then I tried.

        echo "<table style=""width:100%">";
  echo "<tr>";
    echo "<td>Jill</td>";
  echo "</tr>";
  echo "<tr>";
  echo  "<td>Eve</td>";
  echo "</tr>";
echo "</table>";

and I got error Parse error: syntax error, unexpected '"width:100%"' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\1\search.php on line 14

I have no idea whats wrong. any help is really appreciated

Marked as duplicate I have no idea what i'm fixing so unfortunately its no help to me. im sure it will help someone else later down the line.

Image and update Here is an image how it looks now. enter image description here

as you can see the 'Name of movies' is being repeated each time.

Code update

echo '<table style="width:100%">';
  echo "<tr>";
    echo "<td>Name of movie</td>";
  echo "</tr>";
  echo "<tr>";
  echo  "<td>$name</td>";
  echo "</tr>";
echo "</table>";

Update 2

<?php
if (isset($_POST['searchterm'])){
mysql_connect("localhost","root","Oliver");
mysql_select_db("videos");

$search = mysql_real_escape_string(trim($_POST['searchterm']));

$find_videos = mysql_query("SELECT * FROM `videos` WHERE `keywords` LIKE'%$search%'");
while ($row = mysql_fetch_array($find_videos, MYSQL_BOTH)) {
{

    $name = $row['name'];
}
}
}
?>
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
  <head>
  <link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
  <link rel="icon" type="image/ico" href="images/favicon.ico">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<style type="text/css">
  .vjs-default-skin .vjs-control-bar { font-size: 125% }
</style>
    <meta charset="utf-8">
    <title>Network TV | search</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link href="css/font-awesome.css" rel="stylesheet" />
    <link href="css/3.1.1/animate.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/styles.css" />
  </head>
  <body style="overflow-x: hidden">
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Network TV</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class=""><a href="\1\index.php">Home</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
        <div class="v-center">
                <h1 class="text-center" style="color:white">Welcome to Network TV</h1>
                <table class="table" style="width:10%">
                        <thead>
                            <tr>
                                <th>Movie name</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><?php echo $name; ?></td>
                            </tr>
                        </tbody>
                    </table>
        </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

    <script src="js/scripts.js"></script>
</html>
Oliver Ketley
  • 83
  • 1
  • 1
  • 13
  • In line 14 you wrote echo "`";`... Remove the second " and it will work
    – Luca Schimweg Jul 18 '15 at 21:04
  • Now noting is being displayed, the error has gone but no results are being shown. – Oliver Ketley Jul 18 '15 at 21:05
  • Your HTML is badly-quoted. In the first code example you have `echo "";` - there are three double quotes. You want `echo "
    "`. In the final code example you have `echo "
    ";`. Using the same style of quotes for both your PHP and HTML code will confuse the PHP parser, so you should differentiate between the two. E.g. `echo '
    ';`
    – Aurel Bílý Jul 18 '15 at 21:05
  • Updated post please have a read, thanks – Oliver Ketley Jul 18 '15 at 21:10
  • @OliverKetley So what do you get now with your updated code? – Rizier123 Jul 18 '15 at 21:36
  • Hey, it displays one result only, the last entry to the database that is. – Oliver Ketley Jul 18 '15 at 21:37
  • if you could help it would be amazing – Oliver Ketley Jul 18 '15 at 21:40
  • @OliverKetley Well you still have the table tag and these stuff in your loop. So move everything out of the loop which you don't want to have in there, e.g. `echo ""; echo ""; while($row = mysql_fetch_assoc($find_videos)) { echo ""; } echo ""; echo "
    " . $row["name"] . "
    ";`
    – Rizier123 Jul 18 '15 at 21:40
  • @OliverKetley Now you show us some different code. But with your code in update 2 your problem is, that you overwrite the variable in each iteration of your while loop. So change your while loop to something like this: `while($row = mysql_fetch_assoc($find_videos)) { $names[] = $row["name"];}` then later, when you want to use your fetched names change your current code: ` ` to something like this: ` ` – Rizier123 Jul 18 '15 at 21:46
  • I'm extremely new to programming, iv'e replaced the while statement and nothing happens, it displays nothing. I dont know where to put the rest of the code you supplied. – Oliver Ketley Jul 18 '15 at 21:50
  • @OliverKetley Your code should look something like this: http://pastebin.com/m5RL7u7z – Rizier123 Jul 18 '15 at 21:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83637/discussion-between-rizier123-and-oliver-ketley). – Rizier123 Jul 18 '15 at 21:53

0 Answers0