Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.