php解析错误,出现意外的';'在第12行,但没有错

时间:2019-08-22 10:46:33

标签: php

第12行存在问题(显示该行的注释)。显然有一个意外的';' (分号)。尽管唯一的分号是关闭移至下一行之前总是需要的特定行。

 <?php
// creating a master if to see if the submit button was pressed.
if (isset($_POST['signup-submit'])) {
// connecting to the database validation file in the same file.
  require 'dbh.inc.php';
  $username = $POST['username'];
  $email = $POST['email'];
  $password = $POST['password'];
  $repeatPassword = $POST['repeat_password'];
  //error handlers time!!
  if (!filter_var($email,FILTER_VALIDATE_EMAIL && !preg_match("/^[a-zA-Z0-9]*$/",$username)) {
    header("Location: ../signup.php?error=invalidemailusername");  //this is line 12 with the issue
    exit();
  }

  else if (!preg_match("/^[a-zA-Z0-9]*$/",$username)) {
    header("Location: ../signup.php?error=invalidusername&email=".$email);
    exit();
  }
  

解析错误:语法错误,意外的';'在第12行(没有用于隐私的文件位置)

2 个答案:

答案 0 :(得分:1)

此:

if (!filter_var($email,FILTER_VALIDATE_EMAIL && !preg_match("/^[a-zA-Z0-9]*$/",$username)) {

应该是这样

if (!filter_var($email,FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/",$username)) {

答案 1 :(得分:-2)

已解决

请检查此代码

(!filter_var($email,FILTER_VALIDATE_EMAIL && !preg_match("/^[a-zA-Z0-9]*$/",$username)) here add one bracket

 if (!filter_var($email,FILTER_VALIDATE_EMAIL && !preg_match("/^[a-zA-Z0-9]*$/",$username))) {
    header("Location: ../signup.php?error=invalidemailusername");  //this is line 12 with the issue
    exit();
  }