Ok I have asked this question before and nobody even has a clue on how this can be done. Hopefully you guys are smarter than my Professor (Hes a little slow to begin with)! Ok I have a combo box that can have Multiple selections and check this out... I want all those selections to be able to be inserted into the Database. We are using MySQL and the field is set to Text. Ok so I was trying to make this script just to see what the output is.. well am I retarted or do I not understand what is wrong with my script? This should work... Keyword == SHOULD..... 🙂

<?php
if(isset($go)){
echo"$box";
exit;
}
?>

<body>

<form method="POST" action="showbox.php">
<p><select size="5" name="box" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></p>
<p><input type="submit" value="Submit" name="go"></p>
</form>

</body>

Any help would be greatly appreciated... Thanks!

Chad R. Smith
President of Broken Formula
www.brokenformula.com

    Um, I just tried the script, and it works just fine.

    You did say, "all of the selections," but, of course, you know you can only select one at a time.

    But it does show up just fine. What's the problem, please?

      Woops.. Sorry for my earlier stupid answer. Here's your code, for MULTIPLE selects!

      <HTML LANG="en">
      <HEAD>
      </HEAD>
      <?php
      if(isset($go)) {
      while (list(,$value) = each ($box)) {
      print "Option $value selected\n";
      }
      }
      ?>
      <body>
      <form method="POST" action="showbox.php">
      <p><select size="5" name="box[]" multiple>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      </select></p>
      <p><input type="submit" value="Submit" name="go"></p>
      </form>
      </body>

        Yep, this guy is right.

        was it just printing the value "Array"?
        that's because you can't just echo the array name, you have to echo (or in your case, insert) each item individually.

          oops again.

          If the visitor does NOT select anything, you'll get an error. So I added an "if($box)" to the code (and an "else" statement, too):

          <HTML LANG="en">
          <HEAD>
          </HEAD>
          <?php
          if(isset($go)) {
          if ($box)
          while (list(,$value) = each ($box)) {
          print "$value\n";
          }
          else echo 'come on, pick a number';
          }
          ?>
          <body>
          <form method="POST" action="showbox.php">
          <p><select size="5" name="box[]" multiple>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          </select></p>
          <p><input type="submit" value="Submit" name="go"></p>
          </form>
          </body>

            Ok thanks for your help... but I was wondering how would I make that all one array? Could I make that all one variable?

            So when I insert I can just insert it by that one variable instead of making it print them seperately? I like your code so far and really think you will be able to help me.. Thank you very much! You are excellent!

            Chad R. Smith
            President of Broken Formula
            www.brokenformula.com

              Write a Reply...