-2

I'm tying to show points in the map by getting latitude, longitude from my Database while the query is (SELECT * FROM trackEmployee) it's retrieving the data and show it on the map (Y)

But when I'm trying to set condition WHERE groupEmail ='$mail' AND date= '$date' by getting data in post it's not working

If I pass the value to the condition directly, It works (Y)

The problem here is to get the data from above php tag to the next php tag which contain the query.

<html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 <title>Google Map API V3 with markers</title>
 <style type="text/css">
 body { font: normal 10pt Helvetica, Arial; }
 #map { width: 750px; height: 400px; border: 0px; padding: 0px; }
 </style>

<?php


$connect_mysql= @mysql_connect($server,$username,$passwor) or die ("Connection Failed!");
$mysql_db=mysql_select_db("GP15",$connect_mysql) or die ("Could not Connect to Database");

$mail=$_POST['sel1'];
echo $mail;  // prints correctly 
$date=$_POST['sel2'];
echo $date;  // prints correctly 

//On page 2
?>

 <script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
 <script type="text/javascript">
 //Sample code written by August Li
 var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
 new google.maps.Size(32, 32), new google.maps.Point(0, 0),
 new google.maps.Point(16, 32));
 var center = null;
 var map = null;
 var currentPopup;
 var bounds = new google.maps.LatLngBounds();



 function addMarker(lat, lng, info) {
 var pt = new google.maps.LatLng(lat, lng);
 bounds.extend(pt);
 var marker = new google.maps.Marker({
 position: pt,
 icon: icon,
 map: map
 });
 var popup = new google.maps.InfoWindow({
 content: info,
 maxWidth: 300
 });
 google.maps.event.addListener(marker, "click", function() {
 if (currentPopup != null) {
 currentPopup.close();
 currentPopup = null;
 }
 popup.open(map, marker);
 currentPopup = popup;
 });
 google.maps.event.addListener(popup, "closeclick", function() {
 map.panTo(center);
 currentPopup = null;
 });
 }
 function initMap() {
 map = new google.maps.Map(document.getElementById("map"), {
 center: new google.maps.LatLng(0, 0),
 zoom: 14,
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 mapTypeControl: false,
 mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 });

  <?php

// $query = mysql_query("SELECT * FROM trackEmployee"); // this query works

 $query = mysql_query("SELECT * FROM trackEmployee WHERE employeeEmail='$mail'AND date='$date'");


 while ($row = mysql_fetch_array($query)){


 $name=$row['street'];
 $lat=$row['latitude'];
 $lon=$row['longitude'];
 $desc=$row['district'];

 echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc')\n");

}

 ?>
 center = bounds.getCenter();
 map.fitBounds(bounds);

 }
 </script>



 </head>
 <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">


 <div id="map"></div>
 </html>
Aya Radwan
  • 181
  • 5
  • 17
  • 1
    Do you know you have whitespace in ' $mail ' and ' $date '? And try to improve your security by checking the values of $mail and $date first before using them in the query ;-) – Stefan Jun 19 '15 at 13:04
  • `mysql` calls are officially deprecated, please switch to `mysqli` or `pdo` – the_pete Jun 19 '15 at 13:07
  • You have whitespace in your query parameters. Remove the leading and trailing whitespace for `$mail` and trailing whitespace for `$date` – Venkat Chintalapani Jun 19 '15 at 13:07
  • I remove the space, it's not working – Aya Radwan Jun 19 '15 at 13:07
  • look at my answer below and try it. – sonam gupta Jun 19 '15 at 13:07
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 19 '15 at 13:08
  • I can only give an *educated* guess as to why it's failing, but my fingers are cramped up *Sam* - @JayBlanchard ;-) – Funk Forty Niner Jun 19 '15 at 13:09
  • Remove the error suppression `@`. – Jay Blanchard Jun 19 '15 at 13:09
  • ...and your echos reveal...? edit: nothing, I'll bet. – Funk Forty Niner Jun 19 '15 at 13:13
  • when I set echo in the second tag the map not appear ! – Aya Radwan Jun 19 '15 at 13:14
  • @Fred-ii- when using var_dump(); the map disappear – Aya Radwan Jun 19 '15 at 13:21
  • `var_dump();` belongs inside PHP. Your map shouldn't be disappearing; it should be showing you what's set or not. – Funk Forty Niner Jun 19 '15 at 13:21
  • 1
    Now to take out *the BIG gun*. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Jun 19 '15 at 13:29
  • the tags are correct if i change the query to SELECT * from trackEmployee; it works good , the map is showed with the points retrieved from the datbase – Aya Radwan Jun 19 '15 at 13:29
  • please be attention with me ! the normal query (SELECT * FROM trackEmployee;) is already works BUT the problem is to pass the variable from the post in the first tag to the other tag! #HELP – Aya Radwan Jun 19 '15 at 13:34
  • `WHERE employeeEmail='$mail'AND date='$date'` - `$mail=$_POST['sel1']; echo $mail; $date=$_POST['sel2']; echo $date; $_SESSION['email'] = $mail; $_SESSION['date'] = $date; echo $mail = $_SESSION['email']; echo $date = $_SESSION['date'];` where is the session started? where are the POST arrays coming from? a form. There. show your form for it. I told you what to use to check for errors. I am done here. Good luck. – Funk Forty Niner Jun 19 '15 at 13:35
  • post arrays is coming from other page when i print here it's printed , while i was trying to get the value from the first tag to the other i t just try to use the $_session,,, anyway I don't want to use it,, I just want to get the data from the first tag and paste it in the second tag ! #HELP :'( – Aya Radwan Jun 19 '15 at 13:40
  • You use session variables but you never start the session. – Jay Blanchard Jun 19 '15 at 13:47
  • okay! I don't want to use the session, i was just trying to use which would may work – Aya Radwan Jun 19 '15 at 13:52
  • @JayBlanchard please check the edit in the code – Aya Radwan Jun 19 '15 at 13:56

1 Answers1

-1

Replace your query with this.Hope it works.

$query = mysql_query("SELECT * FROM trackEmployee WHERE employeeEmail='".$mail."'AND date='".$date."'");
sonam gupta
  • 775
  • 6
  • 17