Member Avatar for cuonic

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

Recommended Answers

All 3 Replies

Member Avatar for cuonic

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 ?

See the manual page. The num_rows function can only be used after store_results. See the example in the manual for the fix.

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.