0

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

Edited by sashtha

2
Contributors
1
Reply
7
Views
2 Years
Discussion Span
Last Post by diafol
0
$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

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.