2014-04-16 127 views
-3

我做了一個簡單的用戶添加/登錄表單,但是我不能使用數組提取或添加數據到數據庫,並且需要簡單的過程。用戶添加/登錄表單問題

<?php 
//User_Add_Page 
    if(isset($_POST['userid'],$_POST['username'],$_POST['password'],$_POST['sex'],$_POST['desig'])) 
    { 

     include("connect.php"); 
     $badchars='[email protected]£$%^&*()+=-][\;/.,`~<>?:"|{} \''; 
     $userid=$_POST['userid']; 
     $username=$_POST['username']; 
     $password=$_POST['password']; 
     $sex=$_POST['sex']; 
     $desig=$_POST['desig']; 
     $errors=array(); 

       if(empty($userid)&& empty($username) && empty($password) && empty($sex) && empty($design)) 
       { 
         $errors[]= "All Fields Require"; 
       } 
       else if($userid=="") 
       { 
         $errors[]= "Enter User ID"; 
       } 

       else if (strpbrk($userid, $badchars) !== false) 
       { 

         $errors[]= 'INVALID User ID...'; 
       } 
       else if(strlen($userid)<5 && $username != "") 
       { 
         $errors[]='User ID Must be Greater than 5 Characters'; 
       } 
       else if(is_numeric ($userid)) 
       { 

         $errors[]= 'User ID Must Conatin Both letters AND character'; 
       } 

       else if(strlen($userid)>20 && $username != "") 
       { 

        $errors[]= 'User ID Must be Less Than 20 Characters'; 
       } 

       else if($username=="") 
       { 

         $errors[]= "Enter username"; 
       } 
       else if(strlen($username)>30) 
       { 

         $errors[]= "Enter username less than 30 char."; 
       } 

       else if(!ctype_alpha(str_replace(' ','',$username)))//search alphabetic char. from username 
       { 

        $errors[]='Name Must be Character Only'; 
       } 
       else if($password == "") 
       { 

        $errors[]= 'Please Enter Password'; 
       } 

       else if(strlen($password)<5 && $password != "") 
       { 

        $errors[]= 'Password Must Be Greater Than 5 Characters'; 
       } 
       else if($desig == "") 
       { 

        $errors[]= 'Please Enter Designation'; 
     } 


      else if(empty($errors)) 
      { 
         $write=("INSERT INTO adduser VALUES ('','$userid','$username','$password','$sex','$desig')"); 


         $time = 1; //Time (in seconds) to wait. 
        $url = "add_user_process.php"; //Location to send to. 
       header("Refresh: $time; url=$url"); 
      } 
} 



?> 
+0

而不是'否則,如果(空($錯誤))'你需要做的'否則,如果(計數($錯誤)<= 0)'這會工作。 –

+0

計數不起作用....解析錯誤:語法錯誤,意外的')'在C:\ xampp \ htdocs \ add_user2.php在第79..it給出這個錯誤 – user2788100

+0

檢查括號可能有你離開或添加一個額外的括號。 –

回答

0
else if(empty($errors)) 
      { 
         $write=("INSERT INTO adduser VALUES ('','$userid','$username','$password','$sex','$desig')"); 

         mysqli_query($write,Your_connection_string) 
         $time = 1; //Time (in seconds) to wait. 
        $url = "add_user_process.php"; //Location to send to. 
       header("Refresh: $time; url=$url"); 
      } 
0

你的 「INSERT INTO」 你必須指定的mysql_query對象, 像$結果= mysql_query($寫)之後;

這樣,

$write="INSERT INTO adduser VALUES ('','$userid','$username','$password','$sex','$desig')"; 
$result = mysql_query($write); 
+0

好的..這個作品...謝謝..非 – user2788100

+0

青梅更多queestion ,,我cnnot顯示錶單錯誤,就像我沒有輸入用戶名,,比,它應該回顯出「輸入用戶名」? – user2788100

+0

檢查[這裏](http://stackoverflow.com/questions/23102300/php-form-validation) – Rorschach