Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
PHP
<?php

$is_invalid = false;

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    
    $mysqli = require __DIR__ . "/database.php";
    
    $sql = sprintf("SELECT * FROM user
                    WHERE email = '%s'",
                   $mysqli->real_escape_string($_POST["email"]));
    
    $result = $mysqli->query($sql);
    
    $user = $result->fetch_assoc();
    
    if ($user) {
        
        if (password_verify($_POST["password"], $user["password_hash"])) {

            
            session_start();
            
            session_regenerate_id();
            
            $_SESSION["user_id"] = $user["id"];
            
            header("Location: index.php");
            exit;
        }
    }
    
    $is_invalid = true;
}

?>


What I have tried:

How can I fix my problem in the above code for line 13?

Error is over here:
Fatal error: Uncaught mysqli_sql_exception: Unknown column 'email' in 'where clause' in D:\xampp\htdocs\e-commerce web\login.php:13 Stack trace: #0 D:\xampp\htdocs\e-commerce web\login.php(13): mysqli->query('SELECT * FROM u...') #1 {main} thrown in D:\xampp\htdocs\e-commerce web\login.php on line 13
Posted
Updated 13-Sep-23 4:16am
v5

Read the error message, it couldn't be any clearer:
Error
Unknown column 'email' in 'where clause'
You are requesting all columns from the user table, and trying to restrict it to specific values of the email column.
But ... there is no column in the user table called email.

We can't fix that - we don't have access to your DB to see what columns you do have!
 
Share this answer
 
solution solved. Thanks.my db put user_email. so dont have email.
 
Share this answer
 
v2
Comments
OriginalGriff 2-Sep-23 2:38am    
You're welcome!

Just so you know in future ... don't post comments like this as solutions - if you use the "Have a Question or Comment?" button instead, then an email is sent to the person you are talking to (just as this sent one to you). If you post as a solution, the only person who could get a notification is you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900