2

好的,我试图让它工作,我似乎无法从我的 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>

连接就在那里,这是我现有表中每次显示的内容:

在此处输入图像描述

我知道您不需要将“id”作为自动增量包含在内,但是,我有一种感觉是导致问题的原因。

任何帮助表示赞赏!

4

2 回答 2

1

改变:

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

至:

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

并为其他人做同样的事情,它会起作用。

于 2013-10-01T15:05:29.947 回答
0

使用mysqli_real_escape_string而不是 mysql_real_escape_string

于 2013-10-01T13:55:21.957 回答