用户添加/登录表单问题

时间:2014-04-16 08:41:29

标签: php mysql

我制作了一个简单的用户添加/登录表单。但是我无法使用数组提取或添加数据到数据库,需要简单的程序。

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

       include("connect.php");
       $badchars='!@£$%^&*()+=-][\;/.,`~<>?:"|{} \'';
       $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");
            }
}



 ?>

2 个答案:

答案 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");
            }

答案 1 :(得分:0)

在你的&#34; INSERT INTO&#34;你必须指定mysql_query对象,     比如$ result = mysql_query($ write);

像这样,

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