简体   繁体   中英

Error message where user don`t exist, php

I am trying to build an web application. When the user try to log in, and the email dont exist or the password is incorrect it stay to index page.What I want is that when the email dont exist or when the password is incorrect to stay in index page, and to display an message:"Email dont exist" in this page...I have tried o lot of things, but nothing function till now...My code is below:

   <?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');
            }
    }

What should I put at this part to display the error message

else{
            header('location:index.html');
            }

Thanks in advance...

我将index.html更改为index.php,然后将其重定向到类似index.php?error = 1的内容。在index.php中,我将检查isset($ _ GET ['error'])和if($ _ GET ['错误'] == 1,您可以输出错误。

Set a session variable with the error message. Then redirect to index.php and there, check to see if the session variable is set. If so, display the error message and clear the session variable.

In your condition:

if ($count > 0){
    session_start();
    $_SESSION['user_id']=$row['Id_Per'];
    header('location:home.php');
}else{
    header('location:index.php?error=404');
}

then in index.php

if($_GET['error']==404){
    echo "Email does not exist";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM