Jump to content

codenoob123

New Members
  • Posts

    2
  • Joined

  • Last visited

codenoob123's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It is a little difficult to use mysql error since I am running the query via an Android application (android to sqlite to php to mysql) After reading your suggestions, I think I will investigate using mysqli library or PDO library and start all over rather than using a tutorial. Thanks.
  2. <p>Hello, I have been following this tutorial and I have an error. Can someone show me where the error stems from and how I can avoid it next time? <?php class DB_Functions { private $db; // put your code // constructor function __construct() { require_once 'DB_Connect.php'; // connecting to database $this->db = new DB_Connect(); $this->db->connect(); } // destructor function __destruct() { } /** * Storing new user * returns user details */ public function storeUser($name, $email, $password) { $uuid = uniqid('', true); $hash = $this->hashSShA($password); $encrypted_password = $hash["encrypted"]; // encrypted password $salt = $hash["salt"]; // salt $result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid','$name','$email','$encrypted_password','$salt',NOW())"); // check for successful store if ($result) { // get user details $uid = mysql_insert_id(); // last inserted id $result = mysql_query("SELECT * FROM users WHERE uid = $uid"); // return user details return mysql_fetch_array($result); } else { return false; } } /** * Get user by email and password */ public function getUserByEmailAndPassword($email, $password) { $result = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error); // check for result $no_of_rows = mysql_num_rows($result); if ($no_of_rows > 0) { $result = mysql_fetch_array($result); $sale = $result['salt']; $encrypted_password = $result['encrypted_password']; $hash = $this->checkhashSSHA($salt, $password); // check for password equality if ($encrypted_password == $hash) { // user authentication details are correct return $result; } } else { // user not found return false; } } /** * Check user is existed or not */ public function isUserExisted($email) { $result = mysql_query("SELECT email FROM users WHERE email = '$email'"); $no_of_rows = mysql_num_rows($result); if ($no_of_rows > 0) { // user existed return true; } else { // user not existed return false; } } /** * Encrypting password * @param password * returns salt and encrypted password */ public function hashSSHA($password) { $salt = sha1(rand()); $salt = substr($sale, 0, 10); $encrypted = base64_encode(sha1($password . $salt, true) . $salt); $hash = array("salt" => $salt, "encrypted" => $encrypted); return $hash; } /** * Decrypting password * @param salt, password * returns hash string */ public function checkhashSSHA($salt, $password) { $hash = base64_encode(sha1($password . $salt, true) . $salt); return $hash; } } ?> my error: mysql_num_rows(): supplied argument is not a valid MySQL result resource
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.