Halpert Posted November 7, 2009 Share Posted November 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/180707-formatting-serialized-array-input/ Share on other sites More sharing options...
Daniel0 Posted November 8, 2009 Share Posted November 8, 2009 What exactly do you mean? Can't just just select the element from the array and use that, and why are you even making it an array in the first place if you don't want it to be one? Quote Link to comment https://forums.phpfreaks.com/topic/180707-formatting-serialized-array-input/#findComment-953416 Share on other sites More sharing options...
Halpert Posted November 8, 2009 Author Share Posted November 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180707-formatting-serialized-array-input/#findComment-953424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.