I am new to php. I want to insert the value selected from dropdown list in mysql database. i have two tables named tbl_user and tbl_domain. how may i storea value in tbl_domain selected from dropdown list. can any1 help me pls? here is ma code. pls tell me whats wrong wid this code? its not inserting a value in table

             <select id = "domainList" name="domainList">
               <option value = "1">Engineering</option>
               <option value = "2">Medical</option>
               <option value = "3">Accountancy</option></select></br>
               //codeto select the value
                $sql = "INSERT INTO tbl_user(first_name,last_name, sex, user_experience, user_dob)
VALUES('".$_POST[firstname]."','".$_POST[lastname]."','".$_POST[sex]."', '".$_POST[experience]."','".$_POST[dob]."' )";
$query = mysql_query($sql);
$user_id = mysql_insert_id();

               $myoption = $_POST['domainList']; 

$mysqlstatement = mysql_query("INSERT into tbl_domain set domain_name=".$myoption.", user_id=".$user_id."");
3 Years
Discussion Span
Last Post by nadiam

as urtrivedi and aleksenator said you have to have your options in a <form></form> and need a save button in order to save the data into database. also seeing as your new to php u need a connection to ur database. just to add INSERT into tbl_domain set domain_name=".$myoption." it should be
' ".$myoption." ' also i dont think u really need the mysql_insert_id() you could just add '' into ur query but make sure its in the order of the columns in ut database table example:


INSERT INTO tablename VALUES('',$name,$age)

but i guess since this post has been a month ago u should know about this right now.

Edited by nadiam

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.