如何在mysql表中保存文本框数据

时间:2015-01-12 09:58:18

标签: php html

我正在使用地图获取该位置的坐标,并将其放在名为“add”的文本框中。当我尝试将从文本框中获取的数据插入表格时,它显示错误。

这是我的代码:

   <html>
<head>
<link href="modal.css" rel="stylesheet" type="text/css" />
 </head>
<body>
<form action="" method="POST">
 <table>
 <tr><td>
    </br>GIS Stamp</td>
        <td><br><input type="text" name="add" id="add" size="31" value="" disabled="disabled"/><a href="#login_form" id="login_pop">
        Select From MAP</a>
                <a href="#x" class="overlay" id="login_form"></a>

        <div class="popup">

             <html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();

function geocodePosition(pos) {
  geocoder.geocode({
    latLng: pos
  }, function(responses) {
    if (responses && responses.length > 0) {
      updateMarkerAddress(responses[0].formatted_address);
    } else {
      updateMarkerAddress('Cannot determine address at this location.');
    }
  });
}

function updateMarkerStatus(str) {
  document.getElementById('markerStatus').innerHTML = str;
}

function updateMarkerPosition(latLng) {
   document.getElementById('info').innerHTML = [
    latLng.lat(),
    latLng.lng()
  ].join(', ');
  add.value=[
    latLng.lat(),
    latLng.lng()
  ].join(', ');
}

function updateMarkerAddress(str) {
  document.getElementById('address').innerHTML = str;
}

function initialize() {
  var latLng = new google.maps.LatLng(12.941320125683307, 74.86030859375);
  var map = new google.maps.Map(document.getElementById('mapCanvas'), {
    zoom: 8,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  var marker = new google.maps.Marker({
    position: latLng,
    title: 'Point A',
    map: map,
    draggable: true
  });

  // Update current position info.
  updateMarkerPosition(latLng);
  geocodePosition(latLng);

  // Add dragging event listeners.
  google.maps.event.addListener(marker, 'dragstart', function() {
    updateMarkerAddress('Dragging...');
  });

  google.maps.event.addListener(marker, 'drag', function() {
    updateMarkerStatus('Dragging...');
    updateMarkerPosition(marker.getPosition());
  });

  google.maps.event.addListener(marker, 'dragend', function() {
    updateMarkerStatus('Drag ended');
    geocodePosition(marker.getPosition());
  });
}

// Onload handler to fire off the app.
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
  <style>
  #mapCanvas {
    width: 500px;
    height: 400px;
    float: left;
  }
  #infoPanel {
  display:none;
    float: left;
    margin-left: 10px;
  }
  #infoPanel div {
    margin-bottom: 5px;
  }
  </style>

  <div id="mapCanvas"></div>
  <div id="infoPanel">
    <b>Marker status:</b>
    <div id="markerStatus"><i>Click and drag the marker.</i></div>
    <b>Current position:</b>
    <div id="info"></div>
    <b>Closest matching address:</b>
    <div id="address"></div>
  </div>
</body>
</html>
            <a class="close" href="#close"></a>

        </div><br></td>

        </tr>
     <!-- panel with buttons -->
            <tr><td>
    <input type="submit" name="submit" value="Insert"></td></tr></table>
    </body>
    </form>
    </html>

    <?php
    if(isset($_POST['submit']))
    {

        $add=$_POST['add'];

        $c=mysql_connect("localhost","root","");
        mysql_select_db("hudadb");

        $ins=mysql_query("INSERT INTO `death` 
                          (GIS)
                          VALUES ('$add')",$c) or die(mysql_error());


    }

?>

我得到的错误是:

  

注意:未定义的索引:添加到D:\ XAMPP \ htdocs \ hudaf \ mainproj \ s \ s.php

1 个答案:

答案 0 :(得分:0)

未提交带有已禁用元素的属性,或者您可以说它们的值未发布。

替换此行代码

<input type="text" name="add" id="add" size="31" value="" disabled="disabled"/>

<input type="text" name="add" id="add" size="31" value="" readonly/>

注意:请记住已禁用字段未通过表单提交提交,您需要使用 readonly