解析错误:语法错误,C:\xampp\htdocs\tlsproject\server.php

解析错误:第 25 行 C:\xampp\htdocs\tlsproject\server.php 中的语法错误,意外的 '}'


看了一遍又一遍,还是没找到错误


<?php


  session_start();


  //initializare variabile


  $username = "";

  $email = "";


  $errors = array();


  //conectare la baza de datefmt_create


  $db = mysqli_connect('localhost','root','','project') or die("Could not connect to database");


  //Inregistrare user


  $username = mysqli_real_escape_string($db, $_POST['username']);

  $email = mysqli_real_escape_string($db, $_POST['email']);

  $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);

  $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);


  //Validare


  if(empty($username)) {array_push($errors, "Username is required")};

  if(empty($email)) {array_push($errors, "Email is required")};

  if(empty($password_1)) {array_push($errors, "Password is required")};

  if($password_1 != $password_2) {array_push($errors, "Passwords do not match")};


  //Unicitate username


  $user_check_query = "SELECT * FROM user WHERE username = '$username' or email = '$email' LIMIT 1";


  $results = mysqli_query($db, $user_check_query);

  $user = mysqli_fetch_assoc($result);


  if($user)

  {

    if($user['username'] === $username){array_push($errors, "Username already exists");}

    if($user['email'] === $email){array_push($errors, "This email is already being used");}

  }


  //Inregistrare user


  if(count($errors) == 0){


    $password = md5(password_1); // encriptare parola

    $query = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', '$password')";

    mysqli_query($db,$query);

    $_SESSION['username'] = $username;

    $_SESSION['success'] = "You are now logged in";


    header('location: index.php');

  }


 ?>

解析错误:第 25 行 C:\xampp\htdocs\tlsproject\server.php 中的语法错误,意外的 '}'


largeQ
浏览 213回答 2
2回答

偶然的你

错误在这里兄弟,大括号后的分号(;)...if(empty($username)) {array_push($errors, "Username is required")};if(empty($email)) {array_push($errors, "Email is required")};if(empty($password_1)) {array_push($errors, "Password is required")};if($password_1 != $password_2) {array_push($errors, "Passwords do not match")};改成这个if(empty($username)) {array_push($errors, "Username is required");}&nbsp; if(empty($email)) {array_push($errors, "Email is required");}&nbsp; if(empty($password_1)) {array_push($errors, "Password is required");}&nbsp; if($password_1 != $password_2) {array_push($errors, "Passwords do not match");}

心有法竹

<?php&nbsp; session_start();&nbsp; //initializare variabile&nbsp; $username = "";&nbsp; $email = "";&nbsp; $errors = array();&nbsp; //conectare la baza de datefmt_create&nbsp; $db = mysqli_connect('localhost','root','','project') or die("Could not connect to database");&nbsp; //Inregistrare user&nbsp; $username = mysqli_real_escape_string($db, $_POST['username']);&nbsp; $email = mysqli_real_escape_string($db, $_POST['email']);&nbsp; $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);&nbsp; $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);&nbsp; //Validare&nbsp; if(empty($username)) array_push($errors, "Username is required");&nbsp; if(empty($email)) array_push($errors, "Email is required");&nbsp; if(empty($password_1)) array_push($errors, "Password is required");&nbsp; if($password_1 != $password_2) array_push($errors, "Passwords do not match");&nbsp; //Unicitate username&nbsp; $user_check_query = "SELECT * FROM user WHERE username = '$username' or email = '$email' LIMIT 1";&nbsp; $results = mysqli_query($db, $user_check_query);&nbsp; $user = mysqli_fetch_assoc($result);&nbsp; if($user)&nbsp; {&nbsp; &nbsp; if($user['username'] === $username) array_push($errors, "Username already exists");&nbsp; &nbsp; if($user['email'] === $email) array_push($errors, "This email is already being used");&nbsp; }&nbsp; //Inregistrare user&nbsp; if(count($errors) == 0){&nbsp; &nbsp; $password = md5(password_1); // encriptare parola&nbsp; &nbsp; $query = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', '$password')";&nbsp; &nbsp; mysqli_query($db,$query);&nbsp; &nbsp; $_SESSION['username'] = $username;&nbsp; &nbsp; $_SESSION['success'] = "You are now logged in";&nbsp; &nbsp; header('location: index.php');&nbsp; }&nbsp;?>注意当代码在 IF 语句所在的同一行时不需要 {}
打开App,查看更多内容
随时随地看视频慕课网APP