地址和坐标不显示在Mysql数据库中

时间:2013-10-01 13:42:51

标签: php html mysql forms

好的,我试图让它工作,我似乎无法从我的PHP表单中获取MySql数据库中存储的地址和坐标。任何帮助都会显着降低我的皮质醇水平:)

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

include('dbconn.php');

$con = mysqli_connect(db_host, db_user, db_pass, db_name);

    $value1 = mysql_real_escape_string($_POST['name']);
    $value2 = mysql_real_escape_string($_POST['address']);
    $value3 = mysql_real_escape_string($_POST['postcode']);
    $value4 = mysql_real_escape_string($_POST['lat']);
    $value5 = mysql_real_escape_string($_POST['lng']);

    $sqlinsert  = "INSERT INTO cafes (name, address, postcode, lat, lng) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5')";

    if (!mysqli_query($con, $sqlinsert)) {
        die('error inserting new record');
    }
    $newrecord = "1 new address added to database";

}
?>


<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>DB Upload</title>
</head>

<body>
<h1>Insert New Address</h1>
 <form id="myForm" method="post" action="index3.php">
 <input type="hidden" name="submitted" value="true">
<fieldset>
<legend>New PLaces</legend>
<label>Name<input type="text" name="name"></label>
<label>Address<input type="text" name="address"></label>
<label>Postcode<input type="text" name="postcode"></label>
<label>Latitude<input type="text" name="lat"></label>
<label>Longitude<input type="text" name="lng"></label>
</fieldset>
<input type="submit" name="sub" value="Submit">
</form>
<?php
echo $newrecord
?>

</body>
</html>

连接在那里,每次都在我现有的表格中显示:

enter image description here

我知道你不需要将'id'作为自动增量包含在内,但是,我感觉这是导致问题的原因。

任何帮助表示赞赏!!

2 个答案:

答案 0 :(得分:1)

更改:

$value1 = mysql_real_escape_string($_POST['name']);

$value1 = mysqli_real_escape_string($con,$_POST['name']); 

并为其他人做同样的工作。

答案 1 :(得分:0)

使用mysqli_real_escape_string代替mysql_real_escape_string