我创建了级联dropodown表单,但数据未插入db中

时间:2019-04-29 07:12:09

标签: php

  1. 与数据库的连接和我的插入代码。我的下拉菜单中的数据没有插入。
<?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 个答案:

答案 0 :(得分:0)

由于您是在单引号内调用变量而不进行串联,因此应该像下面这样

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

答案 1 :(得分:0)

您应该定义mysqli连接并在查询中使用它。

<?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);
    }

或者您可以使用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);