DB_name: test
Tablename:option
attribute:name char(5);

index.php

<html> <head> <title>OPTION</title> </head> <body> <form method="post" action="index.php" >
Name :

<select name="nameoption"> <option value="name1">name1</option> <option value="name2">name2</option> <option value="name3">name3</option> <option value="name4">name4</option> </select><br> <input type="submit" name="submit"> </form> </body> </html> <?php
include("database/db_conection.php");

if(isset($_POST['submit']))
{
    $name1=$_POST['nameoption'];
    $insert_data=("insert into option ('name') VALUE ('$name1')");
    if(mysqli_query($dbcon,$insert_data))
    {
        echo "insert sucess fully";
    }
    else
    {
        echo mysqli_errno($dbcon);
    }

}
?>
db_connection.php
<?php
try{
$dbcon=mysqli_connect("localhost","root","pass") or die("Could not connected");
mysqli_select_db($dbcon,"test");
}
catch(exception $msg)
{
    echo $msg;

}

?>

this program run partially because the out show return value "1064 ".the record was not insert into database

Member Avatar for diafol
$insert_data=("insert into option ('name') VALUE ('$name1')");

...is wrong, try...

 $insert_data= "INSERT INTO `option` (`name`) VALUES ('$name1')";

Do not enclose column names in single quotes - you need to use backticks. See DW Tutorial: Common Issues with MySQL and PHP - Issue #3

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.