hi,i am new to daniweb,glad to be a member of such wonderful community,

what i am trying to build a google map where user can find a train location by entering the train name into the search box.

i have two php file one is gmap.php which is outputing the train data from database in xml,

and my mymap.php is using gmap.php as GDownloadUrl

when the user is sumbiting the form ,its calling mymap.php

what i am trying to is pass that text value into my gmap.php so that i can write a query like this

"SELECT * FROM markers WHERE train_no="$_post['textboxvalue']'";

creating session isnot working.

my gmap.php


function parseToXML($htmlStr) 
return $xmlStr; 

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
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 = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());

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

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  echo '<marker ';
  echo 'train_id="' . parseToXML($row['train_id']) . '" ';
  echo 'desc="' . parseToXML($row['desc']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';

// End XML file
echo '</markers>';


my mymap.php
<?php echo $_session['a'];?>
<!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">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps AJAX + MySQL/PHP Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg"

    <script type="text/javascript">

    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon(); 
    iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["vehicle"] = iconBlue;
    customIcons["bar"] = iconRed;

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(47.614495, -122.341861), 13);

        GDownloadUrl("gmap.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var train_id = markers[i].getAttribute("train_id");
            var desc = markers[i].getAttribute("desc");
            var type = markers[i].getAttribute("type");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
            var marker = createMarker(point, train_id, desc, type);

    function createMarker(point, train_id, desc, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + train_id+ "</b> <br/>" + desc;
      GEvent.addListener(marker, 'click', function() {
      return marker;


  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>

and the html form
<form method="post" action="mymap.php">
  train name: <input type="text" name="a"><br>
   <input type="submit" name="submit" value="Submit Form"><br>

Recommended Answers

Firstly use CODE tags for posting ur code.
What is working in ur code and what is not working??
Are you not able to generate xml?
Here is a link to add markers using xml.

Jump to Post

All 2 Replies

please help,i am stuck here.

Firstly use CODE tags for posting ur code.
What is working in ur code and what is not working??
Are you not able to generate xml?
Here is a link to add markers using xml. http://econym.org.uk/gmap/basic3.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.