2013-09-28 71 views
0

我有一個註冊頁面進行註冊的學生,但我的網頁會反映那裏有一個錯誤與我的花括號問題用兩個大括號PHP

解析錯誤:語法錯誤,在C意想不到的「}」:\ Program Files文件\的EasyPHP-5.3.3 \ WWW \ Enrollment_System-www.webdevelopplus.com \ enrolsys \ registerwrite.php第65行

來源

<?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_][email protected][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") 
    } 
     } 

?> 

我應該如何調整這些{}在我的if和else語句中?

+0

哪裏是線65? – ComFreek

+3

您的腳本容易受到SQL注入和跨站腳本攻擊。 – Gumbo

+0

Gumbo是對的,你必須確保你正確地進行消毒。 –

回答

0

將整個代碼更改爲此;

<?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_][email protected][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") 
      } 
     } 
    } 
?> 

確保您已在定義的變量,如果()檢查

+0

刪除最後一個支架會使您的答案錯誤。除此之外,它和我的答案一樣... – OIS

+0

我編輯了我的帖子。 –

+0

感謝imran現在工作 – Sizwe

1

你,如果這兩條線

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

     $query = "SELECT * FROM members WHERE Username='$username'"; 
-1

之間句。刪除最後一個「}」缺少的。

這些php標籤中沒有任何東西打開該塊。當它告訴你你在65線上有一個不需要的時候,總是先試着去65線,然後去掉它:)

另外,我認爲你的意思是要有一個「如果」符合那個括號,因爲它是縮進。也許你意外刪除了它?

錯誤是有原因的。

+0

不,最後一個支架是有原因的。格式不好,所以你不能真正看到它。 – OIS