如何修复“解析错误:语法错误,意外的'}”

时间:2019-04-13 03:54:55

标签: php

我正在使用if语句,但似乎无法找到我要去哪里,我对PHP还是很陌生,所以如果有人可以向正确的方向指导我,那就太好了,谢谢。 / p>

我试图重写整个代码,并尝试在代码末尾添加更多的“}”,这似乎根本不起作用。

<?php
$username = "";
$email = "";
$errors = array();

    //Connect to the database
    $db = mysqli_connect('localhost', 'root', '', 'registration');

    //If the register button is clicked
    if (isset($_POST['register'])){
        $username = mysql_real_escape_string($_POST['username']);
        $email = mysql_real_escape_string($_POST['email']);
        $password_1 = mysql_real_escape_string($_POST['password_1']);
        $password_2 = mysql_real_escape_string($_POST['password_2']);
        //Ensure that the form fields are filled correctly.
        if (empty($username)){
            array_push($errors, "A username is required.")}
        if (empty($email)){
            array_push($errors, "An email is required.")}
        if (empty($password_1 != $password_2)){
            array_push($errors, "Passwords do not match.")}
        }

1 个答案:

答案 0 :(得分:0)

在array_push行的末尾错过了分号

if (empty($username)){
    array_push($errors, "A username is required.");
}
if (empty($email)){
   array_push($errors, "An email is required.");
}
if (empty($password_1 != $password_2)){
    array_push($errors, "Passwords do not match.");
}