php mysqli插入错误显示

时间:2016-03-06 17:01:06

标签: php mysql mysqli phpmyadmin sql-insert

我有一个php错误。使用php mysqli insert query我不插入数据。 这是我的代码。请告诉我代码中的错误。

if(isset($_POST['ok'])){

    $uid = "root";
    $pass = "";
    $host = "localhost";
    $db_name = "amoz";

    // Establish Connection
    $conn = mysqli_connect($host, $uid, $pass);

    // Check connection
    if (!$conn) {
         die("Connection failed: " . mysqli_connect_error());
    }else{
         echo "Connected successfully";
         echo "<br/>";
    }

    $first_name = $_POST['first_name_input'];
    $middle_name = $_POST['middle_name_input'];

    mysqli_query($conn, "INSERT INTO g_$51 (f_name,m_name) VALUES ($first_name,$middle_name)");

     }

1 个答案:

答案 0 :(得分:0)

缺少要插入的文字的引号 - 试试这个:

mysqli_query($conn, "INSERT INTO g_$51 (f_name,m_name) VALUES ('$first_name','$middle_name')");