-1

I am currently receiving this error:

SyntaxError: expected expression, got '}' - line 14, col 1

In response to this code block:

    <?php
include_once("base.php");
if(empty($_GET)) {
    $sql = "SELECT * FROM segth";
    $q = mysqli_query($link, $sql);
    if ($r = mysqli_fetch_array($q)) {
        echo "<table border='1'><tr><th>" . $r [1] . "</th></tr>
        <tr><td>$" . $r[2] . "</td></tr><tr><td><input type='text' id='u0name' placeholder='Adjust " . $r [1] . "s Cash' onKeyPress='preupd(event, 0)' /></td></tr></table>";
    }


    while ($r = mysqli_fetch_array($q)) {
        echo "<table class='norm' border='1'><tr><th>" . $r[1] . "</th></tr><tr><td>$" . $r[2] . "</td></tr><tr><td><input type='text' id='u0name' placeholder='Adjust " . $r [1] . "s Cash' onKeyPress='preupd(event, " . $r [1] . ")' /></td></tr></table>";
    }
} else {
    echo "<h1 align='center'>New Game</h1>";
    echo "<table border='1'>
                    <tr><th>Names</th></tr>";
    for($i=0;$i<8;$i++) {
                    echo "<tr><td><input id='u" . $i . "name' placeholder='Player " . ($i+1) . "s Name' /></td></tr>";
        }
        echo "<tr><td><button value='Start' onClick='strt()'>Start</button></table>";
    }
    ?>

I have tried removing several code brackets from around the offending location, but the problem seems to be occuring around line 14 which is the same line the else statement is below. I am currently using Notepad++ to edit this file and so I have a way to see where eah code block starts and finishes by highlighting any { or } and it will highlight the respective beginning or end and there are no orphans here. I just don't understand why I'm getting this error.

This error is causing my scripting to not appear if there is anything in the $_GET array, which causes problems.

user2195574
  • 57
  • 1
  • 8
  • Can't exactly tell since your formatting is a bit off, but it looks like you are trying to do a "while" with an else. That's not a valid php control structure. I also recommend looking into using something that will point out syntax errors like this. – patricksweeney Dec 27 '16 at 21:10
  • 2
    Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – ChrisGPT was on strike Dec 27 '16 at 21:11
  • 1
    Since it's a javascript error instead of a PHP error, look at the source code in the browser to see what's being generated. – aynber Dec 27 '16 at 21:14
  • @patricksweeney The else statement is a continuation of the if statement on line 3. The while is enclosed within the if statement. – user2195574 Dec 27 '16 at 21:23
  • Like I said, I couldn't exactly tell since the formatting in your post was off. – patricksweeney Dec 27 '16 at 21:25
  • @aynber It does appear to be the javasccript code! I've a feeling the app I was using added a spare one for me! Thank you :) – user2195574 Dec 27 '16 at 21:31

2 Answers2

2

It seems you have problem with spaces in string 13.

echo "<table class='norm' border='1'><tr><th>" . $r[1] . "</th></tr><tr><td>$" . $r[2] . "</td></tr><tr><td><input type='text' id='u0name' placeholder='Adjust " . $r[1] . "s Cash' onKeyPress='preupd(event, " . $r[1] . ")' /></td></tr></table>";

I coped your code and detected spaces between $r and [1] on third and fourth possitions. And there are spaces in some other places.

  • I missed that, damn phone editors! i have now amended the code as it should be, however, I am still receiving the exact same error code for the same position. – user2195574 Dec 27 '16 at 21:22
0

Your code seems to have while, else. else does not work with while. If this is a mistake, then try removing the closing bracket just above the while loop. If this does not work how you intended it to, then you may need to restructure your code a little.

Jam1e
  • 43
  • 6