data type point to store lat and longitude

Frens's profile image Frens posted 10 years ago in General Permalink
Hi,

I try the lat and longitude to store in the table
, datatype is POINT !!
$user_ip = getenv(‘REMOTE_ADDR’);
$geo = unserialize(file_get_contents(“http://www.geoplugin.net/php.gp?ip=$user_ip”));
$latitude = $geo["geoplugin_latitude"];
$longitude = $geo["geoplugin_longitude"];
$coords = $geo['geoplugin_latitude'] .’, ‘. $geo['geoplugin_longitude'];

$query .= “point = ‘” . $coords . “‘,”;

But got this error , someone an idea?
Cannot get geometry object from data you send to the GEOMETRY field
i think the way i store is not good.
jfalch's profile image jfalch posted 10 years ago Permalink
postgres ? mysql ?
Frens's profile image Frens posted 10 years ago Permalink
Mysql

Must something like
$query.=" point = POINT({$latitude},{$longitude}) ";

But message
you have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '},{$latitude})..

so first must find out why the error excist
(mysql beginner)
jfalch's profile image jfalch posted 10 years ago Permalink
the code fragment looks like PHP, but it does not appear to be evaluated by PHP (else the },{$ would not be present). what exactly is the complete value of $query immediately before you call the mysql function ?
Frens's profile image Frens posted 10 years ago Permalink
// Build the query
$query = "INSERT INTO test SET ";
//  IP adres 
$ip = $_SERVER['REMOTE_ADDR']; 
$query .=  "ip = '" . $ip . "',";	
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$latitude = $geo["geoplugin_latitude"];
$longitude = $geo["geoplugin_longitude"];
$query.="  point = POINT({$latitude},{$longitude})  ";
$query .= "`date` = '" . mysql_real_escape_string($form->getValue('date')) . "',";
$query .= "`message` = '" . mysql_real_escape_string($form->getValue('message')) . "';"; // Careful! The last line ends in a semi-colon
// Execute the query
mysql_query($query) or die(mysql_error());
// Close the connection
mysql_close();
}
jfalch's profile image jfalch posted 10 years ago Permalink
echo $query (before mysql_query()) would have done it too. if you did this, you would have seen that there is a comma missing after ,{$longitude})
Frens's profile image Frens posted 10 years ago Permalink
$query.=" point = POINT({$latitude},{$longitude}) ";// no comma at the end
tosmile
$query.=" point = POINT({$latitude},{$longitude}), ";


thank you very much Jfalch , that works fine now.

vielen Danksmile
kalvaro's profile image kalvaro posted 10 years ago Permalink
FYI, your PHP code is using the legacy mysql extension, which has been deprecated for several years, it's currently unmaintained and it triggers notices in PHP/5.5 and PHP/5.6. I suggest you check any manual page of the extension for alternatives and start using prepared statements.

Of course, HeidiSQL has absolutely nothing to do with PHPwink

Please login to leave a reply, or register at first.