0

Hi,

Just started to mess with MySQLi, created a simple login script, Connection to MySQL server establishes correctly, but then displays username is incorrect, because 0 rows were returned.

1) Am I doing it right, is the mysqli layout I'm using correct ?
2) Database structure is uid - username - password

Code :

http://pastebin.com/H2CTNzpY

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by decade
0

Just set up a test page with just the mysqli stuff, and the script returns the correct password but $query->num_rows; returns 0. Why is this ?

0

mysqli is much more easier to play than mysql.
in your code

1.declare a connection;

public $connect;

2.create a construct function.

function __construct(){
   $this->connect;
}

I use the $this so that it will call "connect"

  1. create the query
    example INSERT STATEMENT:

    function newUser($data){
    $qry = "INSERT INTO register(name, lastname, email, password, date_created)
    VALUES('".$data['name']."','".$data['lname']."','".$data['email']."',
    '".$data['pass']."', NOW())";
    $sql = $this->connect->prepare($qry);
    $sql->execute();
    $id = $sql->insert_id;
    $sql->close();
    return $id;
    }

OR SELECT STATEMENT

function user($data){
$qry = "SELECT COUNT(email) FROM register WHERE email='".$data['email']."'";
$sql = $this->connect->prepare($qry);
$sql->execute();
$sql->bind_result($data['email']);
$sql->fetch();
$sql->close();
if($data['email'] > 0){
    return true;
}else{
    return false;
}
}

THATS IT. (in philippine language: aral lang ng aral pare)

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.