这个问题在这里已有答案:
我正在使用if语句,我似乎无法找到我出错的地方,我对PHP很新,所以如果有人可以指导我朝着正确的方向,它会很棒,谢谢。
我试图重写整个代码,并通过在代码末尾添加更多“}”进行实验,这似乎根本不起作用。
<?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.")}
}
你错过了分号,在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.");
}