1

I have started to make an app that will retrieve data from a website to an app. I have made a simple php file but it gives me the error:

Parse error: syntax error, unexpected '$con' (T_VARIABLE) in /srv/disk10/2052804/www/poolswag.co.nf/service.php on line 5

I looked online but people getting this same error have noticed that they were missing a semi colon while mine has a semi colon

Any help would be appreciated

    <?php
     
    // Create connection
   -----> line 5 $con=mysqli_connect("http://www.poolswag.co.nf/","2052804_swag”,”test5350”,”2052804_swag");
     
    // Check connection
    if (mysqli_connect_errno())
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
     
    // This SQL statement selects ALL from the table 'Locations'
    $sql = "SELECT * FROM PoolInfo";
     
    // Check if there are results
    if ($result = mysqli_query($con, $sql))
    {
        // If so, then create a results array and a temporary one
        // to hold the data
        $resultArray = array();
        $tempArray = array();
     
        // Loop through each row in the result set
        while($row = $result->fetch_object())
        {
            // Add each row into our results array
            $tempArray = $row;
            array_push($resultArray, $tempArray);
        }
     
        // Finally, encode the array to JSON and output the results
        echo json_encode($resultArray);
    }
     
    // Close connections
    mysqli_close($con);
    ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
al exx
  • 75
  • 1
  • 8

2 Answers2

3

You see the curly/smart quotes in this?

("http://www.poolswag.co.nf/","2052804_swag”,”test5350”,”2052804_swag")
                                           ^ ^        ^ ^

That's what's causing the error.

("http://www.poolswag.co.nf/","2052804_swag","test5350","2052804_swag")

and are two different animals altogether.

You may have copied some code from the web which probably wasn't encoded properly, or are using some type of Word processor instead of a code "editor".

Consult the following for a list of some code editors and added information:

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • That fixed that issue but now it doesnt like the $sql = SELECT * FROM ... Parse error: syntax error, unexpected '$sql' (T_VARIABLE) in /srv/disk10/2052804/www/poolswag.co.nf/service.php on line 15 – al exx Feb 07 '16 at 19:59
  • @alexx add `or die(mysqli_error($con))` to `mysqli_query()` if it's an SQL error. what exactly does it not like? – Funk Forty Niner Feb 07 '16 at 20:00
  • @alexx the error doesn't seem to correspond to what you posted. Line 15 is `// Check if there are results` - are you accessing this from your own PC and how? `http://localhost/file.php` or `c:///file.php`? or more code above that or an included file? – Funk Forty Niner Feb 07 '16 at 20:02
  • @alexx also your line 5 does not correspond also. There's nothing on line 5 for what you posted for code. If you have an included file somewhere that's using the same code or same quotes, then you need to find those. There isn't much else I can see that would cause that, sorry. – Funk Forty Niner Feb 07 '16 at 20:09
2

You need to use " or ' character in defining method's parameters but you use . Replace the wrong characters and everything should work fine.

Grzegorz Gajda
  • 2,424
  • 2
  • 15
  • 23