无法使用mysqli将数据插入MySQL

时间:2015-09-28 18:01:49

标签: php mysql

我是所有php和我的sql的新手。 我有问题,插入数据到mysql。 代码运行良好,包括与数据库的连接,但在插入数据的行为中没有发生任何事情。 mysql在主机服务器上。 它可以是什么? 这是我的代码的一部分:

$host = "localhost";
$user = "user";
$pw = "password";
$db = "database";
$link = mysqli_connect($host, $user, $pw, $db);
if (!$link) {
    die("Could not connect: " . mysqli_connect_error());
}
$query = "INSERT INTO lids (sireal, first_name, face_name, telephone, age, email, date) VALUES (null,'$first_name','$face_name','$telephone','$age','$from','$date')";
mysqli_query($link,$query); 
mysqli_close($link);
header('Location:http://www.ttttt/?mess=1 ');
exit;

2 个答案:

答案 0 :(得分:0)

尝试在插入查询的列名上添加刻度。此外,无论何时运行数据库查询,请确保包含错误处理,例如die(mysql_error())以获取与mysql或mysqli相关的错误定义。

答案 1 :(得分:0)

这里的错误似乎是你要插入的空值,你在表结构中定义了以便串行可以接受空值。

You haven't even assigned values to your variable you are using in insertion .
You can declare them and can assign values as before the query.
$first_name="test";
$face_name="john";
$telephone=566777888;
$age = 26;
$from = 'test@example.com';