Jump to content

[SOLVED] error - need help debugging.


phpgurl

Recommended Posts

I'm trying to learn to use both php and the google maps api.  I made a file that works without using php, but now I'm hoping to do the same connecting to a database.  I'm getting this error:

 

Parse error: syntax error, unexpected $end in /home/site_user_name/public_html/exercises/geocoder2.php on line 79

 

 

Line 79 is at the end of my file.  It's blank.  Here is the code i'm using:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<?php $connection = mysql_connect("localhost", "user", "pw");

if (!$connection){

die("Could not connect to the database: <br/>" . mysql_error());

}

 

 

$db_select = mysql_select_db("database");

if (!$db_select) {

 

die ("could not select the database: <br />". mysql_error());

}

    $query = "SELECT * FROM location";

    $result = mysql_query( $query );

if (!$result){

die ("Could not query the database: <br />". mysql_error());

}

 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){

    $street=$row["street"];

    $city=$row["city"];

    $stateabbr=$row["stateabbr"];

    $zipcode=$row["zipcode"];

?>

 

  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

    <title>Google Maps API Example - Geocoding API</title>

    <script src="http://maps.google.com/maps?file=api&v=2.x&key=xxxxxx" type="text/javascript"></script>

    <script type="text/javascript">

    //<![CDATA[

 

    var map = null;

    var geocoder = null;

 

    function load() {

      if (GBrowserIsCompatible()) {

        map = new GMap2(document.getElementById("map"));

        map.setCenter(new GLatLng(37.4419, -122.1419), 13);

        geocoder = new GClientGeocoder();

 

      <?php

        echo "showAddress('$street, $city, $stateabbr $zipcode');";

        ?>

      }

    }

 

    function showAddress(address) {

      if (geocoder) {

        geocoder.getLatLng(

          address,

          function(point) {

            if (!point) {

              alert(address + " not found");

            } else {

              map.setCenter(point, 13);

              var marker = new GMarker(point);

              map.addOverlay(marker);

              marker.openInfoWindowHtml(address);

            }

          }

        );

      }

    }

    //]]>

    </script>

  </head>

 

  <body onload="load()" onunload="GUnload()">

   

      <div id="map" style="width: 500px; height: 300px"></div>

 

  <?php

  mysql_close($connection);

?>

  </body>

</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.