Jump to content

[php/mysql] Update Rows With A Values Pick From A Listbox


Guest eagle0473
 Share

Recommended Posts

Guest eagle0473

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...