Skip to content Skip to sidebar Skip to footer

Insert Values From A Drop Down List To Database Table

I am new to PHP. When i am trying to insert the value from drop down list to database table showing some errors the code OPTION

Solution 1:

you have to change the name of your table (option). Option is a mysql keyword and so it will cause syntax error while executing queries with php.

Change the table name to option_test or something and make appropriate changes in your php code too. Then it will work.

Also start using mysqli_ or PDO since mysql_ has been deprecated from PHP5 onwards.

Solution 2:

Html Code Is:

<selectname="a"><optionvalue="val1">value1<option><optionvalue="val2">value2<option><optionvalue="val3">value3<option></select>

PHP Code Is:

<?php$a=$_POST[a];
?>

The above php code will help you to fetch data from the selected option into php variable $a. From there on ou can insert your data into the query simply as you inserted before.

Solution 3:

in your code mysql_query("insert into option (name) values ('$name')",$c); here is no need to add connection variable to that function.you can just write mysql_query("insert into option (name) values ('$name')")or die(mysql_error()); reason for calling function mysql_error() is that you came to know what type of error is coming.. and another thing is you should change the name of your table from option to option1 or anything else...then it will work fine..no worry...:)

Solution 4:

please use POST not GET because you want to insertdatas in datdabse. like this :

<formaction="option.php"method="post`">

Post a Comment for "Insert Values From A Drop Down List To Database Table"