我一直在寻找问题的答案,但不幸的是,这样模糊的要求无法解决我的问题。简而言之,我试图执行一条SQL语句以将用户输入的PHP变量插入到我的数据库中。以下是我必须调试问题但最终没有成功的理论列表:
因此,我从理论上讲问题是由于某种原因,PHP如何处理纬度较长的坐标。在数据库中,这些列对于Lat定义为DECMINAL(10,8),对于Long定义为DECIMAL(11,8)。我还检查了变量是否已正确保存/传递。下面是我的PHP代码。
<?php
session_start();
if (empty($_POST['age']) || empty($_POST['year']) || empty($_POST['lat']) || empty($_POST['long'])) {
echo "All variables are not set. Please try again.";
} else if (strlen($_POST['age']) !== 2) {
echo "Please provide a valid age between 11-99";
} else if (strlen($_POST['year']) !== 4) {
echo "The year must be a four digit numeral, and cannot be < 1900";
} else if ($_POST['year'] < 1900) {
echo "You cannot enter a year before 1900, please try again.";
} else {
$gender = htmlspecialchars($_POST['gender']);
$age = htmlspecialchars($_POST['age']);
$year = htmlspecialchars($_POST['year']);
$lat = $_POST['lat'];
$long = $_POST['long'];
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('Y-m-d');
$time = date('H:i:s');
echo $lat;
echo $long;
if ( $gender == 'male') {
$locGend = 'male';
} else {
$locGend = 'female';
}
$username = "user";
$password = "pass";
$hostname = "host";
$database = "database";
$server = new mysqli($hostname, $username, $password, $database);
$sql = "INSERT INTO points (gender, age, year, date, time, ip, lat, long) VALUES ('$gender', '$age', '$year', '$date', '$time', '$ip', '$lat', '$long')";
$results = mysqli_query($server, $sql);
}
?>
最后,我试图从mysqli中获取一些错误信息,但是它从不打印任何错误。
以下是供参考的DBeaver工作查询:
INSERT INTO territory.points (gender,age,`year`,lat,`long`)
VALUES ('male',43,1823,32.81014527,-79.956007);