Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple option selections, how to pass to MySQL 1

Status
Not open for further replies.

peterv12

Technical User
Dec 31, 2008
108
0
0
US
I have a form with an "option box" (I'm not sure if that's the correct term). You can select 1 or more options. I've never used one where multiple options can be selected. What I want to be able to do is insert them into a MySQL database. I'm not sure how this would be done in the PHP, or MySQL. I'm assuming it would be some kind of an array, but I haven't gotten into using arrays yet. Can someone point me to an example that might work? The code for my "option box" is:

Code:
      <div class="required">
        <label for="skills">Required Skills:</label>
        <select name="skills" id="skills" class="selectMultiple" size="8" multiple="multiple">
          <option value="sql">SQL</option>
          <option value="perl">Perl</option>
          <option value="php">PHP</option>
          <option value="html">HTML</option>
          <option value="shell">Shell Scripting</option>
          <option value="perl">Perl</option>
          <option value="jcl">JCL</option>
          <option value="cobol">COBOL</option>
        </select>
        <small>Use <kbd>CTRL</kbd> to select more than one.</small>
      </div>

I appreciate any and all suggestions/comments!
Peter V.
 
Change the select name to: skills[].
Then the receiving script will receive skills as a zero indexed array.

i.e. Array ( [skills] => Array ( [0] => perl [1] => php [2] => html ) )

<div class="required">
<label for="skills">Required Skills:</label>
<select name="skills[]" id="skills" class="selectMultiple" size="8" multiple="multiple">
<option value="sql">SQL</option>
<option value="perl">Perl</option>
<option value="php">PHP</option>
<option value="html">HTML</option>
<option value="shell">Shell Scripting</option>
<option value="perl">Perl</option>
<option value="jcl">JCL</option>
<option value="cobol">COBOL</option>
</select>
<small>Use <kbd>CTRL</kbd> to select more than one.</small>
</div>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top