vendredi 31 janvier 2020

My website doens't recognize any db on localhost

I'm creating a website on localhost using Xampp and PhpMyAdmin to create a db. When I try to use my function to subscribe with username and password, it seems that the db doesn't work: my site displays me that accepted the input but in the user table on phpMyAdmin I can't find the new user just added. I don't know if the problem is the query or the connection to db itself. Is there away to debug it? Sorry for my bad English

I have this php function that is included in all my pages that requires db

<?php
    function db_connection() {
        $db = "mysql:dbname=movie;host=localhost";
        try {
            return new PDO($db, "root", "");
        } catch(PDOException $e) {
            print("Fail to access to db");
        }
    }

I have this php file for the login

<?php include ("database.php");?>
<?php
        function new_user($name, $password)
        {
            $psw = md5($password);
            $db = db_connection();
            $qname=$db->quote($name);
            $qpassword=$db->quote($psw);
            $db -> query(" INSERT INTO Users (id, name, password) VALUES (null, $qname, $qpassword)");
        }

        function check_existent_user($name)
        {
           $db = db_connection();
           $qname=$db->quote($name);
           $rows= $db -> query("SELECT name FROM Users WHERE name = $qname");
           foreach ($rows as $row) {
                return $name == $row["name"];
           }
        }

        function check_password($name, $password)
        {
            $psw = md5($password);
            $db = db_connection();
            $qname = $db->quote($name);
            $rows = $db->query("SELECT password FROM Users WHERE name = $qname");
            if($rows)
            {
                foreach ($rows as $row) {
                    $correct_pass = $row["password"];
                    return $psw === $correct_pass;
                }
            } else {
                return FALSE;
            }
        }



Aucun commentaire:

Enregistrer un commentaire