Guest eagle0473 Posted June 19, 2009 Share Posted June 19, 2009 Hi all ,I've a listbox multiple and when pick some values from list below <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> I would like to UPDATE some rows to a table like example below +------+------+-------------- | id | column1 | column2 | | 22 | LS19/EDC | one | | 23 | LS19/EDC | two | | 24 | LS19/EDC | three | | 25 | LS19/EDC | one | | 26 | LS19/EDC | two | | 27 | LS19/EDC | three | I wrote this code, but does not work correctly <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> <?php $con = mysql_connect('localhost','root',''); if (!$con) { die('Not connect to database: ' . mysql_error()); } mysql_select_db('my_db', $con); $mycount = count($test); while($mycount){ $mycount--; mysql_query("UPDATE table SET column2='$test[$mycount]' WHERE column1 LIKE 'LS19/EDC'"); } ?> Help me please and thank you for the answers Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 You need to get $test from $_POST, and you're not checking if the form was submitted, you're just always running the PHP code. You can check if $_POST['test'] is set and only run the code if so. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.