Jump to content

Formatting serialized array input?


Halpert

Recommended Posts

I'm trying to take input from a user-selected array:

 

<p>Topic of Lesson:<br>
<select name="Topic[]" single>
<option>Language</option>
<option>Math</option>
<option>Other</option>
<option>Technology</option>
</select>

 

and save it to a database using serialize:

 

$topic = serialize($_POST[Topic]);

 

It saves successfully to the database, but includes the array value and character count, so the entry into the database for a Technology selection looks like this: a:1:{i:0;s:10:"Technology";}

 

My question; Is there a way to save only the text as the database entry and if so, how do I go about doing that?  Any help, suggestions, or links are welcome and appreciated, thank you in advance!

Link to comment
https://forums.phpfreaks.com/topic/180707-formatting-serialized-array-input/
Share on other sites

Sorry, I'm still really new at this, I guess I don't know how to select a single element out of the array.

 

As to the second part, I made it an array because there are other fields that allow users to select more than one value.  Example:

 

<p>Age Range:<br>
<input type="checkbox" name="Grade[]" value="1-6"> 1st - 6th grade<br>
<input type="checkbox" name="Grade[]" value="6-9"> 6th - 9th grade<br>
<input type="checkbox" name="Grade[]" value="9-12"> 9th - 12th grade<br>
<input type="checkbox" name="Grade[]" value="College"> College level<br>

 

Here the user can select both 6th - 9th grade and 9th - 12th grade as options and I'd like to be able to grab only the 6-9 and 9-12 values and keep those as entries in the field in the db.  I gave my original example because I thought I could make that example work and figure out how to scale it up for multiple selections.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.