drtzb06222 2013-09-28 07:41
浏览 49
已采纳

用大括号php问题

I have a registration page to register students, but my page keeps reflecting theres an error with my curly bracket

Parse error: syntax error, unexpected '}' in C:\Program Files\EasyPHP-5.3.3\www\Enrollment_System-www.webdevelopplus.com\enrolsysegisterwrite.php on line 65

Source

<?php   
    $username =$_POST["newname"];
    $password =$_POST["newpass"];
    $cpassword =$_POST["conpass"];
    $firstname =$_POST["firstName"];
    $lastname =$_POST["lastName"];
    $others =$_POST["others"];
    $email =$_POST["email"];
    $phone =$_POST["phone"];
    $sex =$_POST["sex"];
    $bg =$_POST["bg"];
    $genotype =$_POST["genotype"];
    $dob =$_POST["dob"];
    $address =$_POST["address"];
    $state =$_POST["state"];
    $lga =$_POST["lga"];
    $nationality =$_POST["nationality"];
    $sq =$_POST["sq"];
    $sa =$_POST["sa"];
    $time =$_POST["time"];
    $day =$_POST["day"];
?>

<?php

if ($password !==$cpassword){
    echo "<div align='center'><img src='./images/progress_med2.gif'>";
    include ("./error1.php");
    echo "<center>Sorry, but the password you provided did not match.<p><a href='javascript:window.history.go(-1)'<img src='./images/goback.jpg'></a>";
  include("./error2.php");
exit;
}

if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)){
  echo "<div align='center'><img src='./images/progress_med2.gif'>";
    include ("./error1.php");
    echo "<center>Sorry, but your email address is not valid.<p><a href='javascript:window.history.go(-1)'<img src='./images/goback.jpg'></a>";
  include("./error2.php");
exit;
}
?>

<?php
include("./DB/config.php");

        $query = "SELECT * FROM members WHERE Username='$username'";
        $results = mysql_query($query);

        if(mysql_num_rows($results) > 0) {
        include("./error1.php");
        echo "<center><img src ='./images/userexist.png'>Sorry, but the .$username. you have chosen is already in existence.<P><a href='javascript:window.history.go(-1)'><img src='./images/goback.jpg'></a>";
        include("./error2.php");
    } else {
        $query = "SELECT * FROM members WHERE email='$email'";
        $results = mysql_query($query);

        if(mysql_num_rows($results) > 0) {
        include("./error1.php");
        echo "<center><img src ='./images/userexist.png'>Sorry, but the .$email. you have chosen is already in existence.<P><a href='javascript:window.history.go(-1)'><img src='./images/goback.jpg'></a>";
        include("./error2.php");
    } else {    
        $SQL1 = "Insert into members(username,Firstname,Lastname,Others,Email,Phone,Sex,Blood_Group,Genotype,Date_Of_Birth,Address,State,LGA,Nationality,Security_Question,Security_Answer,createTime,createDate) Values ('','$username','$firstname','$lastname','$others','$email','$phone','$sex','$bg','$genotype','$dob','$address','$state','$lga','$nationality','$sq','$sa','$time','$day')";
        $results1 = mysql_query($SQL1) or die(mysql_error());
        header("Location: ./register_preview.php")
    }
       }

?>

How should I align these {} in my if and else statements?

  • 写回答

3条回答 默认 最新

  • douzhi9635 2013-09-28 07:47
    关注

    Change the whole code to this;

    <?php   
        $username =$_POST["newname"];
        $password =$_POST["newpass"];
        $cpassword =$_POST["conpass"];
        $firstname =$_POST["firstName"];
        $lastname =$_POST["lastName"];
        $others =$_POST["others"];
        $email =$_POST["email"];
        $phone =$_POST["phone"];
        $sex =$_POST["sex"];
        $bg =$_POST["bg"];
        $genotype =$_POST["genotype"];
        $dob =$_POST["dob"];
        $address =$_POST["address"];
        $state =$_POST["state"];
        $lga =$_POST["lga"];
        $nationality =$_POST["nationality"];
        $sq =$_POST["sq"];
        $sa =$_POST["sa"];
        $time =$_POST["time"];
        $day =$_POST["day"];
    ?>
    
    <?php
    
    if ($password !==$cpassword)
    {
        echo "<div align='center'><img src='./images/progress_med2.gif'>";
        include ("./error1.php");
        echo "<center>Sorry, but the password you provided did not match.<p><a href='javascript:window.history.go(-1)'<img src='./images/goback.jpg'></a>";
      include("./error2.php");
    exit;
    }
    
    if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
    {
      echo "<div align='center'><img src='./images/progress_med2.gif'>";
        include ("./error1.php");
        echo "<center>Sorry, but your email address is not valid.<p><a href='javascript:window.history.go(-1)'<img src='./images/goback.jpg'></a>";
      include("./error2.php");
    exit;
    }
    ?>
    
    <?php
    include("./DB/config.php");
    
        if () // define what to check?
        {
            $query = "SELECT * FROM members WHERE Username='$username'";
            $results = mysql_query($query);
    
            if(mysql_num_rows($results) > 0) 
            {
            include("./error1.php");
            echo "<center><img src ='./images/userexist.png'>Sorry, but the .$username. you have chosen is already in existence.<P><a href='javascript:window.history.go(-1)'><img src='./images/goback.jpg'></a>";
            include("./error2.php");
            } 
            else 
            {
            $query = "SELECT * FROM members WHERE email='$email'";
            $results = mysql_query($query);
    
                if(mysql_num_rows($results) > 0) 
                {
                    include("./error1.php");
                    echo "<center><img src ='./images/userexist.png'>Sorry, but the .$email. you have chosen is already in existence.<P><a href='javascript:window.history.go(-1)'><img src='./images/goback.jpg'></a>";
                    include("./error2.php");
                } 
                else 
                {    
                    $SQL1 = "Insert into members(username,Firstname,Lastname,Others,Email,Phone,Sex,Blood_Group,Genotype,Date_Of_Birth,Address,State,LGA,Nationality,Security_Question,Security_Answer,createTime,createDate) Values ('','$username','$firstname','$lastname','$others','$email','$phone','$sex','$bg','$genotype','$dob','$address','$state','$lga','$nationality','$sq','$sa','$time','$day')";
                    $results1 = mysql_query($SQL1) or die(mysql_error());
                    header("Location: ./register_preview.php")
                }
            }
        }
    ?>
    

    Make sure you have defined the variable in if() check

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法