我想知道是否有人能发现我的错误?
解析错误:语法错误,第14行的public_html / sign_up.php中出现意外的T_VARIABLE
对于我的生活,我无法弄清楚我做错了什么。你必须原谅我的无知,我还在努力学习。
include_once("../php/sign_up/connect_db.php");
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['firstname']) && isset($_POST['surname']) && isset($_POST['postcode'])&& isset($_POST['email']) && isset($_POST['phone'])
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$postcode=$_POST['postcode'];
$email = $_POST['email'];
$phone=$_POST['phone'];
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO TABLE 1(firstname, surname, postcode, phone, email) VALUES('$firstname', '$surname', '$postcode', '$phone', '$email')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Thank you for registering.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
非常感谢任何帮助。
亲切的问候, 标记
答案 0 :(得分:3)
您忘记关闭if括号:
更改
if (isset($_POST['firstname']) && isset($_POST['surname']) && isset($_POST['postcode'])&& isset($_POST['email']) && isset($_POST['phone'])
到
if (isset($_POST['firstname']) && isset($_POST['surname']) && isset($_POST['postcode'])&& isset($_POST['email']) && isset($_POST['phone']))
答案 1 :(得分:1)
你错过了右括号:
if ( isset($_POST['firstname']) && isset($_POST['surname']) && isset($_POST['postcode'])
&& isset($_POST['email']) && isset($_POST['phone']) )
^ here
{
^ you probably want this too as you do have the 'else' and closing brackets