2015-10-18 49 views
0

我試圖插入MySQL查詢如下:爲什麼MySQL INSERT查詢拍攝出錯?錯誤是什麼意思?

doSql("INSERT INTO users (userTypeID, memberUsername, memberHashPassword, memberFirstName, memberLastName, memberEmail, memberStreetNumber, memberStreetName, memberSuburb, memberPostcode, memberCountry, memberPhone, memberMobile, memberGender, memberNewsletter, memberImage) VALUES (2, $mUsername, $hashedPassword, $mFirstName, $mLastName, $mEmail, $mStreetNumber, $mStreetName, $mSuburb, $mPostcode, $mCountry, $mPhone, $mMobilePhone, $mGender, $mNewsletter, $destination_path)"); 

而且我發現了以下錯誤:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, , , , , , , ,' at line 1 

我已檢查是否有語法錯誤,像分號失蹤,但我不不明白爲什麼我得到這個。

我的意思是這些字符來自哪裏:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

這裏是doSql功能:

/********** Perform MYSQL Query **********/ 
function doSql($query) { 
// 1. Connect to the database 
$con = mysqli_connect('localhost', 'root', '', 'shahyan_gameon'); 
// 2. Test if connection occured 
if(mysqli_connect_errno()) { 
    die("Database connection failed " . mysqli_connect_error() . "(" . mysqli_connect_errno() . ")"); 
    return false; 
} 
// 3. Do the query 
$result = mysqli_query($con, $query) or die(mysqli_error($con)); 
// mysqli_query runs a query against the database using two argument, the connection and the query string 
//die() stops a script from being processed and outputs info. 
if($result) { 
    return $result; 
} else { 
    return false; 
} 
} 
+0

普萊塞後您的完整SQL語句。 – Bjoern

+0

已經詳細解答了, 請檢查http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – akhilsk

+0

可能重複[MySQL語法錯誤,簡單的INSERT? ](http://stackoverflow.com/questions/7855475/mysql-syntax-error-with-simple-insert) –

回答

1

你需要' [quotes]strings

doSql("INSERT INTO users (userTypeID, memberUsername, memberHashPassword, memberFirstName, memberLastName, memberEmail, memberStreetNumber, memberStreetName, memberSuburb, memberPostcode, memberCountry, memberPhone, memberMobile, memberGender, memberNewsletter, memberImage) VALUES (2, '$mUsername', '$hashedPassword', '$mFirstName', '$mLastName', '$mEmail', '$mStreetNumber', '$mStreetName', '$mSuburb', '$mPostcode', '$mCountry', '$mPhone', '$mMobilePhone', '$mGender', '$mNewsletter', '$destination_path')"); 

它應該可以正常工作。

0

試試這個

doSql("INSERT INTO users (userTypeID, memberUsername, memberHashPassword, memberFirstName, memberLastName, memberEmail, memberStreetNumber, memberStreetName, memberSuburb, memberPostcode, memberCountry, memberPhone, memberMobile, memberGender, memberNewsletter, memberImage) VALUES (2, '".$mUsername."', '".$hashedPassword."', '".$mFirstName."', '".$mLastName."', '".$mEmail."', '".$mStreetNumber."', '".$mStreetName."', '".$mSuburb."', '".$mPostcode."', '".$mCountry."', '".$mPhone."', '".$mMobilePhone."', '".$mGender."', '".$mNewsletter."', '".$destination_path."')"); 
0

語法將值插入使用MySQL是如下表:

INSERT INTO table_name VALUES('strParameter1','strParameter2',intParameter1); 

在你的情況,你應該嘗試:

doSql("INSERT INTO users VALUES(userTypeID, memberUsername, memberHashPassword, memberFirstName, memberLastName, memberEmail, memberStreetNumber, memberStreetName, memberSuburb, memberPostcode, memberCountry, memberPhone, memberMobile, memberGender, memberNewsletter, memberImage) VALUES (2, $mUsername, $hashedPassword, $mFirstName, $mLastName, $mEmail, $mStreetNumber, $mStreetName, $mSuburb, $mPostcode, $mCountry, $mPhone, $mMobilePhone, $mGender, $mNewsletter, $destination_path)");