if(isset($_POST['submit'])){
$uname=$_POST['username'];
$pwd=$_POST['password'];
$acc_type=$_POST['acc_type'];
$_SESSION['user_type']=$acc_type;
if($acc_type=='Teacher'){
$sql="select userid,password from teacherinfo where userid='$uname'";
}
else if($acc_type=='Student'){
$sql="select userid,password from studentinfo where userid='$uname'";
}
else if($acc_type=='Admin'){
$sql="select userid,password from admininfo where userid='$uname'";
}
$query = mysql_query($sql);
$count = mysql_num_rows($query);
if($count>0){
$row_data = mysql_fetch_row($query);
if($row_data[1]==$pwd){
$_SESSION['userid']=$row_data[0];
$url="profile.php";
header("Location:$url");
}
else{
echo "Password Miss match!";
}
}
else{
echo "User not Found!";
}
}
注意:未定義的變量:sql在C:\ xampp \ htdocs \ MJ \ index.php在第39行警告:mysql_num_rows()期望參數1是資源,在線40上的C:\ xampp \ htdocs \ MJ \ index.php任何人都可以幫助我嗎?它的一個登錄表單,但它給出的錯誤
[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-索引) – Henders
使用mysqli_ *或pdo,mysql *已被棄用,並會給你警告。 –
你**不能**使用mysql_xxx函數,這些函數從PHP5.5開始不推薦使用,並且在PHP7中刪除。使用mysqli_xxx或PDO代替:http://php.net/manual/en/intro.mysql.php。此外,**從不**直接在您的SQL查詢中使用用戶輸入:http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php –