php - How can I insert more than two option tag value in separated select tag to database -


index.php

<!doctype html> </html> <body>  <form name="fruits" action="selectexec.php" method="post"> <select name="department"> <option value="apple">apple</option> <option value="mango">mango</option> <option value="orange">orange</option> </select>  <select name="company"> <option value="asus">asus</option> <option value="lenovo">lenovo</option> <option value="acer">acer</option> </select>  <input type="submit" name="submit" /> </form>  </body> </html> 

selectexe.php

<?php include_once('pdo-connect.php'); if(isset($_post['submit'])){ $department=$_post['department']; $company=$_post['company'];   // sql statements $sql = "insert selectformtbl (department,company)values('$department',$company)"; $db->exec($sql); }  ?> 

<select> tag should have multiple attribute.

<select name="department[]" multiple></select> <select name="company[]" multiple></select> 

in php can implode values , store database directly.

$departments = implode($_post['department']); $company = implode($_post['company']); $sql = "insert selectformtbl (`department`,`company`) values ('$department','$company')"; $db->exec($sql); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -