-2

I'm tryign to creat user_login system for my website. And now i got problems with selection of user_info from database , using mysqli and prepared statements . My problem is , that i can't get any output . But i'm using the manual at php.net . Here is what i have got the moment:

<?php
require_once 'php/includes/constants.php';

$connection = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME)or die("Error");

$phone = "0661488342";
$password = "1234";

$query = " SELECT * 
            FROM userinfo
            WHERE phone = ? AND password = ?
            LIMIT 1";

$stmt = $connection->prepare($query);
$stmt->bind_param('ss', $phone, $password);

$stmt->execute();

$res = $stmt->get_result();
$row = $res->fetch_assoc();

echo "Password = ".$row['password'];

The error :

Call to undefined method mysqli_stmt::get_result() in Z:...

Can you advise me something about this ?

Edition 1 PHP version is 5.2.12.(sorry, i forgot this) But the question remains the same . How can i get the user_info ?

Animus
  • 665
  • 12
  • 24

3 Answers3

0

What is your PHP version, and mysql version? You should learn more about MySQLi here: http://www.php.net/manual/en/book.mysqli.php

daminufe
  • 924
  • 1
  • 7
  • 13
0

You need to have PHP 5.3.0 and also this method requires the mysqlnd driver. Othervise you will get this error:

 Call to undefined method mysqli_stmt::get_result()

Which is what appears to be happening to you.

Joe Swindell
  • 684
  • 1
  • 7
  • 18
-1

You have an error in your SQL, which you can detect by checking for errors (in this case it outputs them but there are better ways to handle errors.

if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}

if (!($res = $stmt->get_result())) {
    echo "Getting result set failed: (" . $stmt->errno . ") " . $stmt->error;
}

$row = $result->fetch_row()

In your case password column name is a reserved word in MySQl (there is a PASSWORD function). Your SQL should backtick column names and table names:

$query = " SELECT * 
           FROM `userinfo`
           WHERE `phone` = ? AND `password` = ?
           LIMIT 1";

FINALLY, it looks like you are stroing passwords in the clear which means you are doing it wrong. See PHP The Right Way: Password Hashing

Oscar M.
  • 1,076
  • 7
  • 9
  • Yes, pass is not md5ed, but this is only beta, and i'm only studying . – Animus May 16 '14 at 14:02
  • Even MD5 is not secure for password storage, and if you're studying nothing is better than learning the right way the first time. – Oscar M. May 16 '14 at 14:11