<form action="4.php" method="POST">
<select name="select2[]" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<select name="select[]" multiple>
<option value="volvo1">Volvo1</option>
<option value="saab2">Saab2</option>
<option value="opel3">Opel3</option>
<option value="audi4">Audi4</option>
</select>
<input type="submit" name="sub" value="submit">
</form>
4.php
<?php
mysql_connect("localhost", "root", "");
$db=mysql_select_db("test");
if(isset($_POST['sub'])) {
$r=$_POST['select2'];
$f=$_POST['select'];
$val1 = implode("", $r);
$val2 = implode("", $f);
$r=mysql_query("insert into test1 (test,test1) values ('$val1','$val2') ");
}
?>
I am working in a php language . I am using select multiple and trying to add the values in my database but all the values in one row only
INSERTstatement on the database, so it's only going to insert one row. You're also explicitly usingimplode()to turn the arrays into single values for a single row. It sounds like what you want to do is loop through the arrays and execute multiplemysql_query()calls, one for each row to be inserted into the database. (Also, you definitely want to look into usingmysqliinstead ofmysql, and using prepared statements and parameterized queries. Currently your code is vulnerable to SQL Injection attacks.)