0

I would like to incorporate this code into current PHP script:

$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "GoogleMaps";
$vessel = "Test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
};

$sql = "SELECT Coordinates FROM $vessel order by id desc limit 1";

$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
    $myLatlong = $row['Coordinates'];
};

$conn->close();

The server is complaining about line:

$myLatlong = $row['Coordinates'];

with the error:

PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Could somebody please give me an indication what could be wrong here, as this same code is working in a PHP script that includes only this code, it is not working only when I copy/paste it into a current script?

Dominik
  • 311
  • 1
  • 4
  • 11
  • Please provide the code you are trying to paste it into. This is a parsing error so chances are you have a syntax issue in the new file. – d1str0 Feb 29 '16 at 05:20
  • before while `$myLatlong = '';` and in while `$myLatlong .=$row['Coordinates'];` – Alive to die - Anant Feb 29 '16 at 05:23
  • The only difference is that I am trying to insert that code into "heredoc", but do not know how that differs from regular PHP? – Dominik Feb 29 '16 at 05:24
  • you dont show the code that produces the actual error. Also heredoc is a string, so inserting "that code" in to a string makes no sense –  Feb 29 '16 at 05:29
  • 1
    Avoid using `;` at the end of `if and while` closing loop `( }; ) to ( } )` – Nehal Feb 29 '16 at 05:30
  • That was the problem inserting code into a heredoc. – Dominik Mar 01 '16 at 02:03

0 Answers0