我刚刚写了一个简单的代码,在我的数据库中插入一行称为配置文件,但它不起作用。
代码:
<?php
$mysqli= new mysqli("localhost", "****", "****", "****");
if (mysqli_connect_errno()) {
throw new Exception("Unable to connect to the database. Error number: " . $this->mysqli->connect_errno);
}
$result = mysqli_query($mysqli,"INSERT INTO 'profiles' VALUES ( aaa , aaa , aaa , aaa , aaa , aaa , 1 , 1 , 0 , aaa , 0 )");
if($mysqli->affected_rows <= 0){
throw new Exception("Unable to add record in the database! Query returned: " . $result);
}
echo "1";
?>
我的数据库:
1 username varchar(20)
2 password varchar(200)
3 email varchar(20)
4 name varchar(20)
5 city varchar(200)
6 address varchar(200)
7 mf varchar(5)
8 pp varchar(5)
9 reputation varchar(20)
10 register_date varchar(20)
11 kh_f varchar(5)
和错误日志:
[18-Jul-2014 12:32:50 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to add record in the database! Query returned: ' in /home/***/***/***/**/test.php:9
Stack trace:
#0 {main}
thrown in /home/***/***/***/**/test.php on line 9
提前感谢!
答案 0 :(得分:1)
请使用mysqli_error()
来解决您的错误;)
并在字符串中添加引号:$result = mysqli_query($mysqli,"INSERT INTO profiles VALUES ( 'aaa' , 'aaa' , 'aaa' , 'aaa' , 'aaa' , 'aaa' , '1' , '1' , '0' , 'aaa' , '0' )");
答案 1 :(得分:1)
"INSERT INTO 'profiles' VALUES ..."
不是'profiles'
,而profiles
的按钮位于1(!)
左侧我无法写入此符号,因为bbcode会将其解析为代码