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
Post a Comment