………………..main.php……………………..
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="insert.php" method="post">
<p>
<label for="firstName"> Name:</label>
<input type="text" name="firstName" id="firstName">
</p>
<?php
$user='root';
$pass='';
$db='church';
$db=new mysqli("localhost",$user,$pass,$db);
$combo="<select>";
$sql="select designation from post";
if($result=$db->query($sql));
{
if($result->num_rows)
{
while($row=$result->fetch_object())
{
$combo.="<option>".$row->designation."</option>";
}
$result->free();
}
}
$combo.="</select>";
echo "Designation...... ";
echo $combo."</h2>"."</br>";
?>
<input type="submit" value="Submit">
</form>
</body>
</html>
……………. INSERT.PHP ……………………..
<?php
$link = mysqli_connect("localhost", "root", "", "church");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$first_name = mysqli_real_escape_string($link, $_POST['firstName']);
$sql = "INSERT INTO member (name) VALUES ('$first_name')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
....i want insert my selective item from dropdown to mysql database..pls help