dongliao3450 2016-03-02 10:01
浏览 38

不能用php在数据库中插入数据

What i am trying to do is to create a marker on a map and to save it's data on a table on mysql database. I have already red some answers but i didn't find solution. The problem is that i recieve a message "page not found ".

The part to create the marker works. Here is my code:

<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>

<script>
function initialize() {
  var mapProp = {
    center:new google.maps.LatLng(39.150005, 24.112234),
    zoom:7,
    mapTypeId:google.maps.MapTypeId.HYBRID
  };
  var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

  var latit = <?php echo json_encode($_POST["latitude"]); ?>;
  var long = <?php echo json_encode($_POST["longitude"]); ?>;

  var marker=new google.maps.Marker({
    position:new google.maps.LatLng(latit, long),
  });

  marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

</head>

<body>
<div id="googleMap" style="width:100%;height:1000px;"></div>

<button onclick="myFunction()">Drawing</button>

<p></p>

<script>
function myFunction() {
    var myWindow = window.open("http://notamsforflights.eu/drawing/",        "circle", "width=500, height=500");
}
</script>

</body>

</html>

Here is the link i followed to connect to my database but i get the message "page not found" and nothing happens in my table.

https://developers.google.com/maps/articles/phpsqlajax_v3

And here is my code:

<?php
/* a seperate file with my database info */
 require("phpsqlinfo.php"); 

// Gets data from user's entry
$name = $_POST['name'];
$lat = $_POST['latitude'];
$lng = $_POST['longitude'];
$type = $_POST['type'];

// 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());
}

// Insert new row with user data
$query = sprintf("INSERT INTO markers " .
         " (id, name, latitude, longitude, type ) " .
         " VALUES (NULL, '%s', '%s', '%s', '%s', '%s');",
         mysql_real_escape_string($name),
         mysql_real_escape_string($lat),
         mysql_real_escape_string($lng),
         mysql_real_escape_string($type));

$result = mysql_query($query);

if (!$result) {
  die('Invalid query: ' . mysql_error());
}

?>

I checked the info of my database and they are correct. For your information i use wordpress for my site.

I would appreciate any help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧