0

我的错误是什么?

解析错误:语法错误,第 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 is 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);
    }
?>
4

2 回答 2

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']))
于 2013-04-12T20:53:02.123 回答
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
于 2013-04-12T20:53:27.167 回答