简体   繁体   中英

PHP if statement use in login page

Hello I have been having some issues when using(trying to use) an if statement within my php program, I have looked at tutorials and didnt really understand, so I'm looking for someone to understand where I've gone wrong.

I am making a login system for my computer science project and would like to validate the username and password which then moves onto another page or displays an error message. I understand my code isnt the best but im only a beginner.

<?php


    $username = "username";

    $password = "password";

    $hostname = "localhost";



    error_reporting(E_ALL); ini_set('display_errors', 1);



//connection to phpmyadmin

    $dbhandle = mysqli_connect($hostname, $username, $password, '1012405') or die("Unable to connect to MySQL");






$sqlLogin = "SELECT * FROM users WHERE email='".$_POST['email']."'
 AND password='".$_POST['email']."'
";
        $log = mysqli_query($dbhandle,$sqlLogin) or die("Unable to insert to login");

        if $sqlLogin > 0{
            header('Refresh: 3; url=stockInputForBusiness.html');
}       else{
            echo"Incorrect Credentials";
}



?>

There is a lots of stuff to do in your code you can find it and solve out one by one. Best thing is doing by trying. here is my code of login script you can use it for reference.

     if(isset($_POST['submit']))
        {
         $email= $_POST['email'];
         $password= $_POST['password'];
        $email = addslashes($email);
$password = addslashes($password);
$email = mysqli_real_escape_string($link, $email);
$password = mysqli_real_escape_string($link, $password);

         $seladmin ="SELECT id,UserName,Password FROM login WHERE email='$email' && Password='$password'";
         $SelRecAdmin = mysqli_query( $link,$seladmin );

        $row = mysqli_fetch_array($SelRecAdmin); 

        $tot_num_row=mysqli_num_rows($SelRecAdmin);
        if($tot_num_row >0)
        {
          // echo"sucess";
        }
        else
        {
         // echo"unsucess";
        }

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