1

I have a form that submits data to a MySQL table. Specifically, it's using Gravity Forms, a plugin for WordPress, but this isn't really specifically related to either that plugin or WP. I'm just trying to figure out how to format my data so it gets stored in the right format in MySQL.

I'm using the Google Maps Javascript API to look at a specific field, perform Google Maps' auto-complete to retrieve a place, and then take the name of that place (which is what the API returns) and use the Google Maps Geocoding API to add the latitude and longitude.

I know that I need the information stored in the database like this:

a:3:{s:7:"address";s:12:"101 First St";s:3:"lat";s:10:"25.8018672";s:3:"lng";s:18:"-80.12885949999998";}

So I'm trying to create a value for the input by combining the dynamic stuff I am successfully getting, such as the actual street address, lat and longitude, in a variable like this:

place_shebang = 'a:3:{s:7:"address";s:' + place_name_length + ':"' + theplacename + '";s:3:"lat";s:' + place_lat_length + ':"' + theplacelat + '";s:3:"lng";s:' + place_lng_length + ':"' + theplacelng + '";}';

But that saves the data like so when I view it in MySQL:

s:117:"a:3:{s:7:"address";s:12:"101 First St";s:3:"lat";s:undefined:"40.528263";s:3:"lng";s:undefined:"-78.86381770000003";}";

So my question is, what should I do with place_shebang to get it to store in the proper format?

1
  • This is a function of the code the is doing the actual database insert/update. It is calling serialize on your string. Commented Nov 13, 2015 at 19:46

1 Answer 1

3

Instead of creating a serialized string, recreate the object and have that saved.

$place_shebang = [
  "address" => $theplacename,
  "lat"     => $theplacelat,
  "lng"     => $theplacelng,
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.