-1

I could not figure out if I am doing this right. I am trying to output results from my search, however I am unsure if this is done properly. Plus I'm getting this error.

Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING) in /usr/local/www/project/OlegarioJW/largecoursework/tobakuhome.php on line 152

In addition, I am intending to put it inside a div as well as two of my results into <a> tag as these will have links and they are all inside a variable. Is this how it is done?

Below is my code:

<html>
<header></header>

<body>

<?php
    $serverName = "example.com";
    $dbName = "abc";
    $user = "abc";
    $pass = "abc";

    $connection = mysqli_connect($serverName, $user, $pass, $dbName);
    if (!$connection){
        die("Connection failure" . mysqli_connect_error());
    }

?>

<form id ="search" action="tobakuhome.php" method="post">
        <input type="text" name="search" placeholder="Search Game titles here"/>
        <input type="submit" value="Go" />
</form>

<?php print("$output"); ?>

<?php

$output = '';
if (isset($_POST['search'])){
    $searching = $_POST['search'];
    $searching = preg_replace("#[^0-9a-z]#i","", $searching);
} 

    $query = "SELECT * FROM Software WHERE name LIKE '%searching%' OR description LIKE '%$searching%' OR exclusivity LIKE '%$searching%' OR format LIKE '%$searching%'";
    $result = mysqli_query($connection, $query) or die("no results found");
    $count = mysqli_num_rows($query);
    if($count ==0){
        $output = 'Sorry, No results was found.';

    }else{
        while($row = mysqli_fetch_array($query)){
            $Tname = $row['Name'];
            $Tdes = $row['description'];
            $Timg = $row['image'];
            $Texcl = $row['exclusivity'];
            $Tform = $row['format'];
            $Tprice = $row['price'];
            $id = $row['id'];


            $output .= '<div id="data">''<ul id="itemgal">'
            '<li id = "softitem">'
            '<a id= "row" href = "displaysoftware.php?id=" .$id." '.$Tname.' />' '</a>'
            '<a id= "row" href = "displaysoftware.php?id=" .$id." '.$Timg.' />'    '</a>'
            '<br />'
            '<h3>'.$Tform . '</h3>''</td>'
            '<br />'
            '<h4>'.$Texcl . '</h4>''</td>'
            '<h5>' '£' . $Tprice.'</h5>'
            '</li>'
            '</ul>'
            '</div>';
        }
    }

?>
</body>
</html>
codingadventures
  • 2,924
  • 2
  • 19
  • 36
johnobc
  • 571
  • 3
  • 11
  • 25
  • 1
    which one is line 152? – RST Apr 25 '15 at 13:13
  • Also you are trying to print the value of `$output` without assigning it any value first. – Abhishek Patel Apr 25 '15 at 13:18
  • Have you read the documentation page of the [PHP strings](http://php.net/manual/en/language.types.string.php)? Also the page about the [string operators](http://php.net/manual/en/language.operators.string.php) contains the solution to your problem. – axiac Apr 25 '15 at 14:26

3 Answers3

1

Yes! you have string concatenation problem in $output take a look at this code:

<html>
<header></header>

<body>

<?php
    $serverName = "example.com";
    $dbName = "abc";
    $user = "abc";
    $pass = "abc";

    $connection = mysqli_connect($serverName, $user, $pass, $dbName);
    if (!$connection){
        die("Connection failure" . mysqli_connect_error());
    }

?>

<form id ="search" action="tobakuhome.php" method="post">
        <input type="text" name="search" placeholder="Search Game titles here"/>
        <input type="submit" value="Go" />
</form>

<?php print("$output"); ?>

<?php

$output = '';
if (isset($_POST['search'])){
    $searching = $_POST['search'];
    $searching = preg_replace("#[^0-9a-z]#i","", $searching);
} 

    $query = "SELECT * FROM Software WHERE name LIKE '%searching%' OR description LIKE '%$searching%' OR exclusivity LIKE '%$searching%' OR format LIKE '%$searching%'";
    $result = mysqli_query($connection, $query) or die("no results found");
    $count = mysqli_num_rows($query);
    if($count ==0){
        $output = 'Sorry, No results was found.';

    }else{
        while($row = mysqli_fetch_array($query)){
            $Tname = $row['Name'];
            $Tdes = $row['description'];
            $Timg = $row['image'];
            $Texcl = $row['exclusivity'];
            $Tform = $row['format'];
            $Tprice = $row['price'];
            $id = $row['id'];


            $output .= '<div id="data"><ul id="itemgal">'
            .'<li id = "softitem">'
            .'<a id= "row" href = "displaysoftware.php?id="' .$id. '" '.$Tname.' /></a>'
            .'<a id= "row" href = "displaysoftware.php?id="' .$id. '" '.$Timg.' /></a>'
            .'<br />'
            .'<h3>'.$Tform . '</h3></td>'
            .'<br />'
            .'<h4>'.$Texcl . '</h4></td>'
            .'<h5>£' . $Tprice. '</h5>'
            .'</li>'
            .'</ul>'
            .'</div>';
        }
    }

?>
</body>
Sumit
  • 1,619
  • 1
  • 11
  • 24
0

You forgot single quotes around $id in $output variable and then, when you have string spread on more lines, you need to use a dot . in the end of each row, of don't close the string by quote.

$output .= '<div id="data"><ul id="itemgal">' .
                                              ^
            '<li id = "softitem">' .
                                   ^
            '<a id= "row" href = "displaysoftware.php?id="' .$id. '" '.$Tname.' /></a>' .
               ^                                          ^       ^                     ^
            '<a id= "row" href = "displaysoftware.php?id="' .$id. '" '.$Timg.' />'    '</a>'
//                                                        ^       ^
Etc. 

Put . at the end of each row in $output var.

pavel
  • 26,538
  • 10
  • 45
  • 61
-1

I think the problem is here:

        $output .= '<div id="data">''<ul id="itemgal">'
        '<li id = "softitem">'
        '<a id= "row" href = "displaysoftware.php?id=" .$id." '.$Tname.' />' '</a>'
        '<a id= "row" href = "displaysoftware.php?id=" .$id." '.$Timg.' />'    '</a>'
        '<br />'
        '<h3>'.$Tform . '</h3>''</td>'
        '<br />'
        '<h4>'.$Texcl . '</h4>''</td>'
        '<h5>' '£' . $Tprice.'</h5>'
        '</li>'
        '</ul>'
        '</div>';

You can't just put strings next to each other like that, you need to concatenate them with .. Or don't end and start the strings at all.

        $output .= '<div id="data"><ul id="itemgal">
        <li id = "softitem">
        <a id= "row" href = "displaysoftware.php?id="' .$id.'" '.$Tname.' /> </a>
        <a id= "row" href = "displaysoftware.php?id="' .$id.'" '.$Timg.' /> </a>
        <br />
        <h3>'.$Tform . '</h3></td>
        <br />
        <h4>'.$Texcl . '</h4></td>
        <h5>£' . $Tprice.'</h5>
        </li>
        </ul>
        </div>';
Barmar
  • 741,623
  • 53
  • 500
  • 612