<?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){ //用從數(shù)據(jù)庫(kù)取出的密碼和提交的密碼比較
?
? ? ? ? ? ? ? ? echo "<script language=javascript>alert('登錄成功');</script>";?
? ? ? ? Header("Location:addhc1.php");?
? ? ? ? //跳轉(zhuǎn)到指定頁(yè)面?
?
? ? }elseif($cmp_pwd1 == $pwd && $quan == $fx){
? ? ? ? echo "<script language=javascript>alert('用戶名或密碼錯(cuò)誤');</script>";?
? ? ? ? Header("Location:bddhc1.php"); //重新載入頁(yè)面?
?
? ? } else{?
? ? ? ? echo "<script language=javascript>alert('用戶名或密碼錯(cuò)誤');</script>";?
? ? ? ? Header("Location:login1.php"); //重新載入頁(yè)面?
?
? ? }
?
}?
?>?
?
<html>?
? ? <head>?
? ? <title>登錄窗口</title>?
? ? <meta http-equiv="Content-Type" content="text/html" charset="utf-8">?
? ? </head>?
? ? <body>?
? ? <form action="login1.php" ?method="post">?
? ? ? ? 用戶名:?
? ? ? ? <input type="text" name="user" />?
? ? ? ? 密碼:?
? ? ? ? <input type="password" name="pwd" />?
? ? ? ? <br/>?
? ? ? ? <輸入類型=“隱藏”名稱=“已提交”值=“1”/>?
? ? ? ? ?
? ? ??
? ? 表格>?
? ?
?
</html>?
你的查詢語(yǔ)句 ? ?少了一個(gè)單引號(hào) ? 你可以按照我這樣寫 ?$sql = 'select * from name where user ='.$user; ? ?
$sql = 'select * from name where user="'.$user.'"';?
變量名用單引號(hào)。
PHP中,雙引號(hào)里可以使用變量,你可以這么寫:
$sql = “select * from name where user='$user';";?