我有以下函数,用文字说明并验证它们。如果它们有效,则将它们插入到数据库中。一旦插入,检查它们是否被成功插入。如果不返回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