I have a form field where someone can post a google maps (html) url which I then want to put into the database. Then I am retrieving it to use the html embedded map directly on my page. I have tried using urlencode() and htmlspecchars() but:
a) I’m not sure if $_POST is mishandling the data in the first place
b) I’m not sure the best way to store a long url like this in mySQL
The database entry is fine, it goes in, but not all of it. Not sure where it’s getting chopped up. My db col is VARCHAR set to 4000.
html:
<p class="form-title">Google map link</p>
<textarea id="map_link" cols="100" rows="5" name="maplink_entry"></textarea>
php database entry:
$map_link_entry = $_POST['map_link_entry'];
$safe_map_link_entry = mysql_real_escape_string($map_link_entry);
$query_do_entries = mysql_query("INSERT INTO all_places VALUES ('',(NOW()), '$address_entry','$safe_map_link_entry', '$username_entry', '$like', '$dislike', '$source')");
php database retrieval:
$result = '';
while ($row = mysql_fetch_assoc($query)) {
$result .= '<li>';
$result .= stripslashes($row['map_link']);
$result .= '</li>';
}
Roughly, a gmaps url is around 1134 chars but this is all I get back out:
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q
Any help much appreciated…thanks.
I solved this by using PHP to regenerate all the map code, and just added in the user’s search terms stored in the database. This is better than storing the entire link which is unnecessary and cumbersome to prepare in PHP anyway.
This also means the user does not need to get and post an entire google maps link. I just ask them for a location, then attempt to refine it using the googlemaps query strings (http://querystring.org/google-maps-query-string-parameters/).
Final output code is: