我做了一個簡單的用戶添加/登錄表單,但是我不能使用數組提取或添加數據到數據庫,並且需要簡單的過程。用戶添加/登錄表單問題
<?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)'這會工作。 –
計數不起作用....解析錯誤:語法錯誤,意外的')'在C:\ xampp \ htdocs \ add_user2.php在第79..it給出這個錯誤 – user2788100
檢查括號可能有你離開或添加一個額外的括號。 –