1

I'm using php and mysql and I have a problem with inserting latitude and longitude values along with the degree, min and sec symbols. that is (°,',") symbols.

I have referred several sites and tried different ways but i just can't solve it.

First i tried copying symbols and concatenating with the 3 user input values.

$latitude=$degree.'°'.$min.'''.$sec.'?'.'N';

Then after executing the insert query,the $latitude variable value is inserted in database, but the symbols are replaced by random characters as shown here.

2˚3ʼ4ˮN (data stored in database)

Then i tried using html character code instead of symbols.

$latitude=$degree.'&deg'.$min.'&#8217'.$sec.'#8221'.'N';

But it doesn't work.It displays the same html characters in databse.

I don't know whether it is a problem with html entities or something.

pavel
  • 26,538
  • 10
  • 45
  • 61
sao
  • 83
  • 1
  • 7

2 Answers2

2

In my opinion such values should be stored without including its ( DMS : Deg Min Sec ) formatting .

In other words , I might store latitude/longitude ( for example ) as a float value and would apply required formatting when displaying .

Just for example :

  • You would store a date as 2015-04-23 but might display it as 4th April, 2015 .

  • You might store an amount as 10.50 but might display it as $10.50 USD .

Coming to latitude/longitude considering 36°19'11.46" N as example , one of these ways might apply to your situation :

  • Store it as 36.31985 but use required conversion to display it as 36°19'11.46" N .

  • Store it as 36D19M11.46S N but use required string manipulation to display it as 36°19'11.46" N .

  • Store it as four parts lat_deg , lat_min , lat_sec , lat_dir but use concatenation to display it as 36°19'11.46" N .

Links that might help :

mysql-convert-degree-minutes-seconds-to-degree-decimal

latitude-and-longitude-datatype-and-storage-format

convert-dd-to-dms-in-mysql

converting-latitude-and-longitude-coordinates-between-decimal-and-degrees-minutes-seconds

whats-the-best-way-to-store-co-ordinates-longitude-latitude-from-google-maps

Community
  • 1
  • 1
Uours
  • 2,517
  • 1
  • 16
  • 21
  • Thank you for your suggestion, i have tried that too and it is working fine, but my clients was it as one attribute in table. There is no further calculation using this data.Just for storing. – sao Apr 23 '15 at 06:15
  • I would also think having it in one column is better but my my advise would be not to include the formatting within possibly . Please check my updated answer . – Uours Apr 23 '15 at 12:18
1

Try this function:

 $result = mysqli_real_escape_string();

refer following link

http://php.net/manual/en/mysqli.real-escape-string.php

Dipak Dendage
  • 628
  • 1
  • 6
  • 25