PHP没有插入数据库

时间:2017-04-20 08:14:57

标签: php mysql

我正在尝试将数据插入到数据库表中我已经复制了代码PHPmyadmin让我将数据插入到数据库中。我也研究了其他类似的问题,并发现我一直在使用后退滴答我没有使用可能阻止这种工作的保留字。 代码如下:

<?php
// Connect to MYSQL
$connect = mysqli_connect("localhost", "username", "password", 
"Test_downtime");
if (!$connect) {
  die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully\n";
$sql = mysqli_query("INSERT INTO `Test_downtime`.`Downtime` (`ID`, 
`Server_Name`, `Average_downtime`, `Last_downtime`) VALUES (NULL, \'Test\', 
\'3224\', \'2222\')");
if (mysqli_query($sql)) {
  echo $servername . "has been updated";
} 
else{
  echo "Error: " ."<br>" . mysqli_error($sql);
}
?>

我想知道这里是否有人有任何关于为什么不插入的想法。

1 个答案:

答案 0 :(得分:0)

mysqli_query(连接,查询)需要两个参数

<?php

    $connect = mysqli_connect("localhost", "username", "password","Test_downtime");

        if (!$connect) 
        {
            die("Connection failed: " . mysqli_connect_error());
        }else
        {
            echo "Connected successfully\n";
        }


    $sql = mysqli_query($connect, "INSERT INTO `Downtime` (ID, 
    Server_Name, Average_downtime, Last_downtime) VALUES (NULL, 'Test', 
    3224,2222); ");

    if ($sql == true) 
    {
      echo $servername . "has been updated";
    } 
    else
    {
      echo "Error: " ."<br>" . mysqli_error($sql);
    }
    ?>