我正在尝试构建一个Web应用程序。当用户尝试登录,电子邮件不存在或密码不正确时,它会保留到索引页面。我想要的是当电子邮件不存在或密码不正确时留在索引页面中,并显示消息:此页面中的“电子邮件不存在”...我尝试过很多东西,但到目前为止没有任何功能...我的代码如下:
<?php
mysql_connect("127.0.0.1","root","") or die("Smund te lidhet me serverin");
mysql_select_db("axhenda") or die("Kjo databaze nuk u gjet");
if (isset($_POST['submit'])) {//kontrollo per butonin submit
$Email=$_POST['email'];//variable ang $Username kag ang $_POST['UserName'] ay value sang textbox nga UserName
$Fjalekalimi=$_POST['pass'];//variable ang $Username kag ang $_POST['Password'] ay value sang textbox nga Password
$result = mysql_query("SELECT * FROM perdoruesi where Emaili = '$Email' AND Fjalekalimi = '$Fjalekalimi'") or die("Kjo query nuk mund te plotesohet");
$count=mysql_num_rows($result);//isipon kn may tyakto sa query
$row=mysql_fetch_array($result);//ma return row sa database
if ($count > 0){//kun may tyakto sa query e execute yah ang code sa dalom
session_start();//para mag start ang session
$_SESSION['user_id']=$row['Id_Per'];//kwaon ang id sang may tyakto nga username kag password ang ibotang sa $_SESSION['member_id']
header('location:home.php');
}
else{
header('location:index.html');
}
}
我应该在此部分放置什么来显示错误消息
else{
header('location:index.html');
}
提前致谢...
答案 0 :(得分:0)
我会将index.html更改为index.php,然后将它们重定向到index.php?error = 1 在index.php里面,我会检查是否isset($ _ GET ['error'])和if($ _ GET ['error'] == 1,你可以输出错误。虽然我很简单。
答案 1 :(得分:0)
使用错误消息设置会话变量。然后重定向到 index.php 并在那里检查会话变量是否已设置。如果是,则显示错误消息并清除会话变量。
答案 2 :(得分:0)
在您的情况下:
if ($count > 0){
session_start();
$_SESSION['user_id']=$row['Id_Per'];
header('location:home.php');
}else{
header('location:index.php?error=404');
}
然后在index.php
if($_GET['error']==404){
echo "Email does not exist";
}