我正在從數據庫中提取記錄以匹配用戶輸入的網站上工作,如果數據與數據庫中的詳細信息不匹配,它必須顯示一個JavaScript警告框。但問題是JavaScript框也顯示身體負荷。以下是我的代碼:在php中使用javascript警報
//Storing the value of form's username and password into PHP variables
$username = $_POST['username'];
$password = $_POST['password'];
//This query is to check whether ther user has provided valid details
$query = mysql_query("Select * from accounts where username='$username' and password='$password'");
$status = mysql_num_rows($query);
/**Now checking whether the number of rows returned by database are greater than 0 to verify the login
if number of rows are greater than zero we will redirect the user to index page with a session variable**/
if($status >0)
{
$_SESSION['username'] = $username;
?>
<meta http-equiv="refresh" content="0;url=index.php">
<?}
else
{?>
<script language="javascript">
alert('UserName or Password does not match. Please try again');
</script>
<?}?>
的java!=的JavaScript。 –
**警告**您的代碼極易遭受SQL注入攻擊。也應該**從不**將用戶密碼存儲在數據庫中。 –
@Jessica布朗尼完成丹尼爾說的話,我建議你尋找密碼散列(並且永遠不要只散列密碼,總是包含鹽和其他部分,如用戶名,如果它是恆定的)。 –