liquidd Posted July 24, 2007 Share Posted July 24, 2007 Hey all, I am still learning PHP, which is the best language for database driven sites. I am using Dreamweaver CS3 with the devleopers toolbox which is "ok" to help take the guess work out of things. I am using a simple registration form that i made with the toolbox, but when I come to a multiple list to choose from (populated from the database) it doesn't work correctly. Of course, out of the multiple items selected only the last one gets inserted. From what I have read, the selection must be turned into an array then looped for this to work. Is this correct? Next how would I code this to work right. If you let me know which code to post, I will post it. Thanks for all your help!! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 24, 2007 Share Posted July 24, 2007 Yes, you must name the select tag as an array with square brackets. Take this example: <?php if(isset($_POST['submit'])){ foreach($_POST['select'] as $value){ echo 'You selected '.$value.'<br />'; } } ?> <form action="<?php echo $_SERVER['phpself']; ?>" method="post"> <select name="select[]" multiple="multiple"> <option value="var1">Var 1</option> <option value="var2">Var 2</option> <option value="var3">Var 3</option> <option value="var4">Var 4</option> <option value="var5">Var 5</option> </select> <br /> <input type="submit" name="submit" /> If you were to select all 5 options, the output would be: You selected var1 You selected var2 You selected var3 You selected var4 You selected var5 Quote Link to comment 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.