1. Connection to the database and my insert code. My data from my dropdown isn't inserting.
<?php
   include('config.php');
    if(isset($_REQUEST["submit"]))
   {
       $name=$_REQUEST["name"];
       $dateofbirth=$_REQUEST["dateofbirth"];
       $source=$_REQUEST["source"];
       $status=$_REQUEST["status"];
       $phoneno=$_REQUEST["phoneno"];
       $branch=$_REQUEST["branch"];

       mysqli_query("insert into wp_dynamic(name,dateofbirth,source,status,phoneno,branch)values('$name','$dateofbirth','$source','$status','$phoneno','$branch')");         
 }
?>

2 Answers

0
Varun Malhotra On Best Solutions

Because you are calling variables inside single quotes without concatenation it should be like below

mysqli_query($con,"INSERT INTO TableName (name,dateofbirth,source,status,phoneno,branch)values('".$name."','".$dateofbirth."','".$source."','".$status."','".$phoneno."','".$branch."')");
0
Kristijan Mikulec On

You should define you mysqli connection and use it in your query.

<?php
   include('config.php');
    if(isset($_REQUEST["submit"]))
    {

        $conn = new mysqli(HOST,USERNAME,PASSWORD,DATABASE);

        $name=$_REQUEST["name"];
        $dateofbirth=$_REQUEST["dateofbirth"];
        $source=$_REQUEST["source"];
        $status=$_REQUEST["status"];
        $phoneno=$_REQUEST["phoneno"];
        $branch=$_REQUEST["branch"];

        mysqli_query($conn,"INSERT INTO wp_dynamic (name,dateofbirth,source,status,phoneno,branch) VALUES ('".$name."','".$dateofbirth."','".$source."','".$status."','".$phoneno."','".$branch."')");

        mysqli_close($conn);
    }

Or you can use this insted of mysqli_query:

$insert = "INSERT INTO wp_dynamic (name,dateofbirth,source,status,phoneno,branch) VALUES ('$name','$dateofbirth','$source','$status','$phoneno','$branch')";

if($conn->query($insert)){

    echo "Insert successful";

}
else{

    echo mysqli_error($conn);

}
mysqli_close($conn);