Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 保存Lat/Long时出错_Php_Mysql - Fatal编程技术网

Php 保存Lat/Long时出错

Php 保存Lat/Long时出错,php,mysql,Php,Mysql,我的代码有什么错误?我只想将标记lat/lng保存在PHP XAMMP中 <form method="post"> <input id="userLat" type="text" name="userlat" /> <input id="userLng" type="text" name="userLng" /> <input type="submit" name="submit" value = "save"/> <?php

我的代码有什么错误?我只想将标记lat/lng保存在PHP XAMMP中

<form method="post">
<input id="userLat" type="text" name="userlat"  />
<input id="userLng" type="text" name="userLng"  />
<input type="submit" name="submit" value = "save"/>

   <?php
    if($_POST["submit"]=="Save")
    {
         $userlat = $_POST['userlat'];
    $userLng = $_POST['userLng'];

    mysql_connect("localhost","root","");
    mysql_connect_db("dbmarker");

    $s="insert into tblmarker (lat,long) values('".$userlat."','".$userlng."')";
if(mysql_query($s))
echo "record saved";
else
echo mysql_error();
}
?>

var ll = markerA.getLatLng();
document.querySelector('#userLat').value = ll.lat;
document.querySelector('#userLng').value = ll.lng;


$\u POST
键周围添加引号

 $fname = $_POST ["fname"];
 $lname = $_POST ["lname"];
如果没有单引号或双引号,php会将
fname
lname
识别为常量,这是您肯定没有的

注:

  • 不要使用mysql函数,因为它们已被弃用。改用mysqli或PDO

  • 通过转义变量或使用准备好的语句来避免sql注入


    • 改用
      mysqli

      改变

          $userlat = $_POST[userlat];
          $userLng = $_POST[userLng];
      


      发生了什么事?你会犯什么错误?预期的行为是什么?实际上,当我单击“保存”按钮时,我没有看到错误,网页将重新加载,但在我看到我的表格后,没有保存lat/long。我想将传输到文本框的lat/long保存到易受攻击的数据库中。这尤其糟糕,因为您使用的mysql根帐户上没有密码。另外,没有函数
      mysql\u connect\u db()
      ,因此您的代码无论如何都不会工作。我已经编辑了我的代码,但仍然没有任何结果。它是否已修复?如果不尝试将
      if($\u POST[“submit”]==“Save”)更改为if(isset($\u POST[“submit”])
      ,并在最顶端添加
      先生,我已经用您想要更改的代码编辑了我的代码,但仍然不起作用我仍然不知道该怎么做我的代码发布了您想要的代码,但当我尝试时,它没有保存在数据库中
          $userlat = $_POST['userlat'];
          $userLng = $_POST['userLng'];