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

 <label>Domain</label>
             <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
                <?php 
                $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."");
>

Before insert value you should post this form. You cannot save value without it.

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:

table1
|id|name|age|

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.