我想修复我的代码问题,即用户个人资料系统。在注册期间,用户设置他们的个人信息,包括地址地址值由API谷歌地图使用.UPDATE查询不起作用。为什么? N.B:数据类型lat,lng是'十进制(10,8)十进制(11,8)'
<?php
include("database.php");
session_start();
$error = "";
if(isset($_POST['submit']))
{
$username = mysql_real_escape_string($_POST['username']);
$name = mysql_real_escape_string($_POST['name']);
$surname = mysql_real_escape_string($_POST['surname']);
$affiliation = mysql_real_escape_string($_POST['affiliation']);
$department = mysql_real_escape_string($_POST['department']);
$address = mysql_real_escape_string($_POST['address']);
$position = mysql_real_escape_string($_POST['position']);
$email = mysql_real_escape_string($_POST['email']);
$web = mysql_real_escape_string($_POST['web']);
$telephone = mysql_real_escape_string($_POST['telephone']);
$mobile = mysql_real_escape_string($_POST['mobile']);
$password = $_POST['password'];
$passwordConfirm = $_POST['passwordConfirm'];
$privacy = $_POST['privacy'];
//validare i valori inseriti dall'utente
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$error = "Inserisci una email valida ";
}
else if (strlen($password < 8)) {
$error = "La password deve contenere almeni 8 caratteri";
}
else if ($password != $passwordConfirm)
{
$error = "Le password devono coincidere!";
}
else {
$error = "Ti sei appena registrato su B";
}
$sql = "INSERT INTO users(username, name, surname, affiliation, department,address,position,email,web,telephone,mobile,password,privacy) VALUES('$username','$name','$surname','$affiliation','$department','$address','$position','$email','$web','$telephone','$mobile','$password','$privacy')";
mysqli_query($database,$sql) or die(mysqli_error($database));
if($address !=''){
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true";
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->status;
if ($status=="OK"){
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;
}
$sql1 = "UPDATE users SET lng='$lng', lat='$lat' WHERE username='$username'";
mysqli_query($database,$sql1) or die(mysqli_error($database));
}
}
?>
答案 0 :(得分:2)
而不是使用AND
,您需要使用逗号,
$sql1 = "UPDATE users SET lng='$lng', lat='$lat' WHERE username='$username'";
答案 1 :(得分:2)
不要使用And并且不要忘记添加反引号:)并且很高兴看到新手完全避免使用mysql_ *:D
$sql1 = "UPDATE `users` SET `lng`='$lng', `lat`='$lat' WHERE `username`='$username'";
答案 2 :(得分:1)
在更新语句中用逗号替换AND