-1

I'm receiving the following error message when I try to run php:

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'query' at line 1

Here's my code. I've looked at similar issues and nothing seems to be working.

<?php

    require("phpsqlajax_dbinfo.php");

    // Start XML file, create parent node

    $dom = new DOMDocument("1.0");
    $node = $dom->createElement("markers");
    $parnode = $dom->appendChild($node);

    // Opens a connection to a MySQL server

    $connection=mysqli_connect ('127.0.0.1', 'chris', 'banks');
    if (!$connection) {  die('Not connected : ' . mysql_error());}

    // Set the active MySQL database

    $db_selected = mysqli_select_db($connection, 'business');
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    }

    // Select all the rows in the markers table

    $query = "SELECT * FROM markers WHERE 1";
    $result = mysqli_query($connection, 'query');
    if (!$result) {
      die('Invalid query: ' . mysqli_error($connection));
    }

    header("Content-type: text/xml");

    // Iterate through the rows, adding XML nodes for each

    while ($row = @mysql_fetch_assoc($result)){
      // Add to XML document node
      $node = $dom->createElement("marker");
      $newnode = $parnode->appendChild($node);
      $newnode->setAttribute("id",$row['id']);
      $newnode->setAttribute("name",$row['name']);
      $newnode->setAttribute("address", $row['address']);
      $newnode->setAttribute("lat", $row['lat']);
      $newnode->setAttribute("lng", $row['lng']);
      $newnode->setAttribute("type", $row['type']);
    }

    echo $dom->saveXML();

?>
jarlh
  • 42,561
  • 8
  • 45
  • 63
Chris
  • 83
  • 1
  • 9
  • Possible duplicate of [Can I mix MySQL APIs in PHP?](https://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – user3783243 Oct 21 '18 at 20:29
  • 3
    `'query'` is not `$query`. Additionally you can't mix the drivers, use `mysqli` everywhere. Also remove the `where 1`. – user3783243 Oct 21 '18 at 20:30

2 Answers2

0

Change

$result = mysqli_query($connection, 'query');

To

$result = mysqli_query($connection, $query);

Also WHERE 1 doesn't make much sense.

DigiLive
  • 1,093
  • 1
  • 11
  • 28
0

1.First of all,don't mix drivers as you are using mysqli and mysql at the same place. Prefer mysqli as mysql has deprecated.

  1. Change your code from

$result = mysqli_query($connection, 'query');

To

$result = mysqli_query($connection, $query);

because you have stored your sql query in $query variable.

3.avoid "where 1" --simply use SELECT * FROM markers although it seems to work in phpmyadmin but avoid it using in php code.

Hope it works..!!!