我有以下函數,用文字說明並驗證它們。如果它們有效,則將它們插入到數據庫中。一旦插入,檢查它們是否被成功插入。如果不返回false。如果電子郵件無效,首先返回false。 Eclipse + Aptana插件報告最後一個部分的語法錯誤。當我試圖合理化代碼時,它似乎應該正常運行。我可以確認所有{括號}的是在正確的等級秩序如果Else語句語法錯誤
下面是代碼:
public function storeUser($name, $email, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && preg_match('/@.+\./', $email)); { //validate the email
$result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false; //unsuccessful store
}
else { //THIS IS LINE 45
//not a valid email
return false;
}
}
}
它返回以下錯誤:
05-23 11:07:10.758: E/JSON(1601): <b>Parse error</b>: syntax error, unexpected T_ELSE in <b>/home/content/40/8529140/html/webapps/projects/functions/DB_Functions.php</b> on line <b>45</b><br />
05-23 11:07:10.758: E/JSON Parser(1601): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
線45上有什麼? – Neal
在代碼中看到我的評論 – KDEx
你應該真的縮進你的代碼 - 它有助於發現丟失或過時的括號。 – acme