7

I'm new to all of this but I do know a decent amount of HTML/CSS. I want to create a login server and I got most of the code from a video. If someone could help me and explain thoroughly so I can understand it would be greatly appreciated. If any other stuff is needed I will gladly post it.

<?php

require_once 'includes/constants.php';

class Mysql {
private $conn;

function _construct() {
    $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database.');
}

function verify_Username_and_Pass($un, $pwd) {

    $query = "SELECT *
            FROM users
            WHERE username = ? AND password = ?
            LIMIT 1";

    if($stmt = $this->conn->prepare($query)) {
        $stmt->bind_param('ss', $un, $pwd);
        $stmt->execute();

        if($stmt->fetch()) {
            $stmt->close();
            return true;
        }
    }

}
}
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
TheUnCola
  • 301
  • 3
  • 6
  • 11

2 Answers2

11

You need to grant permissions to the user@host in mysql. The grant command looks like

grant all privileges on YOURDB.* to
'YOURUSER'@'localhost' identified by 'YOURPASSWORD';
Kevin Seifert
  • 3,494
  • 1
  • 18
  • 14
  • Where exactly do I put that in? Sorry but I'm new and dont understand a lot of it. Also line 9 is "$this->conn..." – TheUnCola Mar 04 '13 at 19:18
  • You'll need to log into the database interface as the root/admin user to do this. For example, using phpmyadmin, mysql workbench, or the mysql command line client. – Kevin Seifert Mar 04 '13 at 20:37
  • 1
    I entered it on phpmyadmin on the SQL Query and it doesn't give an access denied warning but it says please enter a correct username and password – TheUnCola Mar 04 '13 at 20:57
4

Just a side answer as i came to this answer from my own problem but had a different solution as i knew all privileges were given to the user in question

I was using code such as

        <?php

        session_start();

        $db_host="host";
        $db_user="user";
        $db_pass="mypassword";
        $db_name="dbname";
        $db_table="tblname";

        mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
        mysql_select_db($db_name) or die(mysql_error());

The problem here was that the database password that i had used a generator for included a $ symbol which confused the script and thought there was another variable in starting in

        $db_pass="mypass$word";