sql >> Database >  >> RDS >> Mysql

PHP-weergavenaam van ingelogde gebruiker

Je hebt de naam niet geselecteerd en je haalt hem op.

$sql = 'SELECT email, password, name FROM admin WHERE email = ?';

of

$sql = 'SELECT * FROM admin WHERE email = ?';

zou het probleem moeten oplossen.

Aanvullend:je kunt al je else-statements verwijderen, omdat ze allemaal hetzelfde resultaat geven.

<?php

include_once "inc/user-connection.php";

session_start();

$name = $_POST['name'];
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$email = $_POST['email'];
$username = $_POST['username'];

if (isset($_POST['admin-sign-in'])) {
    if (!empty($email)) {
        if (!empty($password)) {
            $sql = 'SELECT * FROM admin WHERE email = ?';

            // preparing the SQL statement
            if ($stmt = $conn->prepare($sql)) {
                $stmt->bind_param('s', $_POST['email']);
                $stmt->execute();
                $stmt->store_result(); // Store the result so we can check if the account exists in the database.

                // If email exists in sign_up table
                if ($stmt->num_rows > 0) {
                    $stmt->bind_result($email, $password, $name);
                    $stmt->fetch();

                    // if password user enters matches the one in the database
                    if (password_verify($password, $hashed_password)) {
                        $query = mysqli_query($conn, $sql);
                        $row = mysqli_fetch_array($query);
                        $_SESSION['name'] = $row['name'];

                        // upon successful login, redirect user to landing apge
                        header("location: dashboard.php");
                        die();
                    }
                }
                $stmt->close();
            }
        }
    }
    header("location: ../html/404-error.html");
    die();
}



  1. Kan geen gegevens in de database invoegen met optie (textarea)

  2. ODP.NET Oracle.ManagedDataAccess veroorzaakt ORA-12537 netwerksessie einde van bestand

  3. MySQL gebruiken om saldi van af- en bijschrijvingen in één tabel te berekenen

  4. Hoe veilig is authenticatie in het mysql-protocol?