0

I want to link my json result to the google map. I have a imei_number in the database which is the password of the user. Once the user enter the right password(imei_number in the database), the system will select the longitude and latitude of the imei_number selected and later link it to the google map's longitude and latitude. The HTML code is:

<form method="post" action="loginServer.php">
    <label> Username: </label> 
    <input type = "text" maxlength = "20" name = "user" id= "user" />
    <br />
    <label> Password: </label>
    <input type = "password" maxlength= "20" name="pass" id= "pass" />
    <br />
    <input type ="Button" onclick="" value="Clear" />
    <input type = "Submit" value = "Login"id= "btn"/>
</p>
</form>

The Google map page is

<script type = "text/javascript">

  function LoadMap(){     
      var mapEdit = {
         zoom: 8,
         center: new google.maps.LatLng($.getJSON('connect.php', function(data) {

            $.each(data, function(key, val) {

            $("ul").append(val.latitude);
        });

    });
, 
  $.getJSON('connect.php', function(data) {
            $.each(data, function(key, val) {

                $("ul").append(val.longitude);
            });
    });
),
    mapTypeId: google.maps.MapTypeId.ROADMAP
} 
var map = new google.maps.Map(document.getElementById("map"), mapEdit);
var marker = new google.maps.Marker({
     position: new google.maps.LatLng(  $.getJSON('connect.php', function(data) {

        $.each(data, function(key, val) {
              $("ul").append(val.latitude);
        });
    });
, 
  $.getJSON('connect.php', function(data) {
        $.each(data, function(key, val) {
            $("ul").append(val.longitude);
        });

    });
),
     map: map,
});
marker.addListener('click', function(){
        infowindow.open(map, marker);
    });
}

</script>

</head> 
<body onload = "LoadMap()">
<div id="map" style="width: 400px; height: 500px;"></div> 

The connect.php is

<?php

include 'linker.php';

$sql = "SELECT * FROM android_data WHERE $pass = 'imei_number'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_array($result)) {

        $data[] = $row; 
        $row["longitude"]);
        $row["longitude"]. " - latitude: " . $row["latitude"]. "<br>";
    }
} else {
    echo "0 results";
}
echo json_encode($data);
mysqli_close($conn);
?> 

The linker.php is

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project_gps";

$user = $_POST['user'];
$pass = $_POST['pass'];

$user = stripcslashes($user);
$pass = stripcslashes($pass);

$conn = mysqli_connect($servername, $username, $password, $dbname);

$user = mysqli_real_escape_string($conn, $user);
$pass = mysqli_real_escape_string($conn, $pass); 
if($conn){
    echo "connected";
}
if (!$conn) {
   die("Connection failed: " . mysqli_connect_error());
}
?>

But they are not all working. Please, what can I do?

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Tosinosu
  • 13
  • 5
  • 1
    Can you be a little more specific ___But they are not all working___ is not really helping us to help you. – RiggsFolly Apr 07 '17 at 09:44
  • First Error: `$sql = "SELECT * FROM android_data WHERE $pass = 'imei_number'";` instead `$sql = "SELECT * FROM android_data WHERE \`imei_number\` = $pass ";` – RiggsFolly Apr 07 '17 at 09:46
  • Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Apr 07 '17 at 09:47
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Apr 07 '17 at 09:48
  • are you trying to mess with google js api code ?! or am I missing something ? shouldn't it be something like : new google.maps.LatLng(46.781367900048, 6.6401992834884) as stated in their doc ? I don't see any UL in there... – OldPadawan Apr 07 '17 at 10:10

0 Answers0