使用php和javascript将我的谷歌地图保存到数据库中



我正在尝试将PHP与Google map JavaScript一起使用,这是我的JavaScript代码,我与PHP的文件名是face.php

    <?php if(isset($_GET['p'])){$p=$_GET['p'];} ?>
<!DOCTYPE html >
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Property Map</title>
<link rel="stylesheet" href="../../../../css/960.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../../../../css/template.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../../../../css/colour.css" type="text/css" media="screen" charset="utf-8" />
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var marker;
    var infowindow;
    function initialize() {
      var latlng = new google.maps.LatLng(30.0599153,31.2620199,13);
      var options = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      var map = new google.maps.Map(document.getElementById("map-canvas"), options);
      var html = "<table>" +
                 "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
                 "<tr><td>Address:</td> <td><input type='text' id='address'/></td> </tr>" +
                 "<tr><td>Type:</td> <td><select id='type'>" +
                 "<option value='bar' SELECTED>bar</option>" +
                 "<option value='restaurant'>restaurant</option>" +
                 "</select> </td></tr>" +
                 "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
    infowindow = new google.maps.InfoWindow({
     content: html
    });
    google.maps.event.addListener(map, "click", function(event) {
    marker = new google.maps.Marker({
      position: event.latLng,
      map: map
    });
    map.setCenter(event.latLng);
    google.maps.event.addListener(marker, "click", function() {
      infowindow.open(map, marker);
    });
});
    }
    function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getPosition();
      var url = "manageMap.php?propid=<?php echo $p; ?>&name=" + name + "&address=" + address +
                "&type=" + type + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message").innerHTML = "Location added.";
        }
      });
    }
    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request.responseText, request.status);
        }
      };
      request.open('GET', url, true);
      request.send(null);
    }
    function doNothing() {}
    </script>
    </head>
    <body style="margin:0px; padding:0px;" onload="initialize()">
    <h1 id="head" class="header_height"><img src="../../../../img/logo.jpg" width="284" height="73" alt="" class="logo"/></h1>
<?php
    if(isset($_GET['cid'])){$cid=$_GET['cid'];}
    if(!isset($_GET['cid'])){$cid=9;}
?>
<ul id="navigation">
  <li class='active'><a href="../../../../index.php?cid=9"><span style="color:#FFFFFF; font-size:16px;">Finish, return to projects</span></a></li>
</ul>
<div id="welcome">
<a style="color:#FFF; font-weight:bold; font-size:14px;" href="session_manager/logout.php">Sign out</a></div>
    <div style="width:100%; height:autox; margin:0 auto;">
<h1 style="margin-right:10px;">Step Three</h1>
<p style="color:#000066; font-size:18px; font-family:Arial, Helvetica, sans-serif; margin:20px;">In this step you should add new map to your property, here is how?<br />Just search for your place on the map and then put you pin there and then write the name and address and save and colse. You are done<br>
  <span style="color:#F50307; font-weight:bold;">*Important</span><br>
    After you pin you place on the Map please don't do any thing else, just click on Finish, return to projects, to avoid any problems.
</p>
<div id="map-canvas" style="width: 100%; height: 600px"></div>
<div id="message"></div>
</div>
</body>
</html>

如您所见,我正在尝试将propid=<?php echo $p; ?>传递到我的 URL 上

在页面顶部,我也有这个

<?php if(isset($_GET['p'])){$p=$_GET['p'];} ?>
<!DOCTYPE html >

获取$p

我尝试使用此.htaccess哪些内容

AddType application/x-httpd-php .js
AddHandler x-httpd-php5 .js
<FilesMatch ".(js|php)$">
SetHandler application/x-httpd-php
</FilesMatch>

但问题是当我尝试面对时.php在服务器上它提供下载face.php而不是打开它。

在这里查看我的问题

现在我该如何解决这个问题,还有其他方法

你的哑剧类型很糟糕。 它们需要设置为文本/HTML for php

为什么你可以使用 JavaScript 来获取你的propid,然后将其传递到你的 URL 中

添加此内容以使您propid

<script type="text/javascript">
    var url = document.URL;
    var id_check = /[?&]p=([^&]+)/i;
    var match = id_check.exec(url);
    if (match != null) {
    final_id = match[1];
    }else {
    final_id = "";
}
    </script>

然后在此处使用相同的 var final_id 来传递您的p

var url = "manageMap.php?propid=+final_id& 

最新更新