<?php
header("content-type:text/html:charset=utf-8");
include("conn.php");
if(isset($_POST['submitted'])){
$user = $_POST['user'];
$ pwd = $_POST['pwd'];
$sql = 'select * from name where user="'.$user.'"';
# //$sql = "select * from name where user = '.$user'";
$result = mysqli_query($conn,$sql) ;
$row = mysqli_fetch_array ($result);
$cmp_pwd = $row['password'];
$quan =$row['quan'];
$xbb = 1;
$fx = 0;
if( $cmp_pwd == $pwd && $quan == $xbb){ //用從資料庫取出的密碼與提交的密碼比較
echo "<script language=javascript>alert('登入成功');</script>"; "Location:addhc1.php");
//跳到指定頁面
# }elseif($cmp_pwd1 == $pwd && $quan }elseif($cmp_pwd1 == $p== && $quan == $fx ){
echo "<script language=javascript>alert('使用者名稱或密碼錯誤');</script>";
” ); //重新載入頁面
} else{
echo "<script language=javascript>alert('使用者名稱或密碼錯誤');<script language=javascript>alert('使用者名稱或密碼錯誤');<script language=javascript>alert('使用者名稱或密碼錯誤');< ;/script>";
Header("Location:login1.php"); //重新載入頁
## }##
}
#
# }##
}
##} ?> #<html> <head> <title>登入視窗</title> <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> </ head> <body> # <form action="login1.php" method="post"> ###### 使用者名稱:# ## 使用者名稱:#o# <input type="text" name="user" /> ###### 密碼: ###### <input type="password" name="pwd" /> ## <br/> ###<輸入類型=「隱藏」名稱=「已提交」值=「1」/>
表格>
</html>
你的查詢語句 少了一個單引號 你可以照我這樣寫 $sql = 'select * from name where user ='.$user;
$sql = 'select * from name where user="'.$user.'"';
變數名用單引號。
PHP中,雙引號裡可以使用變量,你可以這麼寫:
$sql = “select * from name where user=\'$user\';";
#