连接到数据库mysql时出现错误消息

时间:2018-05-18 13:20:13

标签: php mysql

我在连接数据库时遇到问题。 总是收到消息(“消息”:“无法将数据保存到数据库。”) 当我执行寄存器到我的本地服务器。

register.php

  <?php
     error_reporting(0);
      require "init.php";

$fname = $_POST["name"];
$lname = $_POST["password"];
$qualifiers = $_POST["qualifiers"];
$signature = $_POST["signature"];


$sql = "INSERT INTO user_info (id,Fname, Lname, Qualifiers, SigNature) VALUES (NULL, '".$fname."', '".$lname."', '".$qualifiers."', '".$signature."');";
if(!mysqli_query($con, $sql)){
    echo '{"message":"Unable to save the data to the database."}';
}
?>

init.php

    <?php

error_reporting(0);

$db_name = "app";
$mysql_user = "root";
$mysql_pass = "";
$server_name = "localhost";

$con = mysqli_connect($server_name, $mysql_user, $mysql_pass, $db_name);

if(!$con){
    echo '{"message":"Unable to connect to the database."}';
}

?>

0 个答案:

没有答案