2014-07-18 32 views
0

我剛剛寫了一個簡單的代碼插入一行到我的數據庫稱爲配置文件,但它不起作用。不能添加一行數據庫

代碼:

<?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 

在此先感謝!

+1

使用mysqli_error()獲取mysql正在報告的錯誤消息。此外,趕上你的例外。 –

+1

你有你不應該使用的引號,並且引用了你應該使用它們的地方,但你不是。 –

回答

1

請使用mysqli_error()讓你的錯誤;)

並添加引用到你的字符串:$result = mysqli_query($mysqli,"INSERT INTO profiles VALUES ('aaa' , 'aaa' , 'aaa' , 'aaa' , 'aaa' , 'aaa' , '1' , '1' , '0' , 'aaa' , '0')");

+0

您也複製了錯誤''profiles'' – machineaddict

+0

是的,沒有看到這個錯誤 –

+0

thnaks它的工作:) – Mahfa

1
"INSERT INTO 'profiles' VALUES ..." 

'profiles'profiles與按鈕位於上1(!)左側我可以」 t寫這個符號是因爲bbcode將其解析爲代碼