0

I have a problem with the login.

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\wamp\www\droidlogin\funciones_bd.php on line 68

the name of the table is ocbup_users

In the database password is stored encrypted.

funciones_db

 <?php

    class funciones_BD {

        private $db;

        // constructor

        function __construct() {
            require_once 'connectbd.php';
            // connecting to database

            $this->db = new DB_Connect();
            $this->db->connect();

        }

        // destructor
        function __destruct() {

        }

        /**
         * agregar nuevo usuario
         */
        public function adduser($username, $password) {

        $result = mysql_query("INSERT INTO ocbup_users(username,passw) VALUES('$username', '$password')");
            // check for successful store

            if ($result) {

                return true;

            } else {

                return false;
            }

        }


         /**
         * Verificar si el usuario ya existe por el username
         */

        public function isuserexist($username) {

            $result = mysql_query("SELECT username from ocbup_users WHERE username = '$username'");

            $num_rows = mysql_num_rows($result); //numero de filas retornadas

            if ($num_rows > 0) {

                // el usuario existe 

                return true;
            } else {
                // no existe
                return false;
            }
        }


        public function login($user,$passw){

        $result=mysql_query("SELECT COUNT(*) FROM ocbup_users WHERE username='$user' AND passw='$passw' "); 
        $count = mysql_fetch_row($result);

        /*como el usuario debe ser unico cuenta el numero de ocurrencias con esos datos*/


            if ($count[0]==0){

            return true;

            }else{

            return false;

            }
        }

    }


?>
  • Usually this error means that you have some errors in query. Try to print your query and run it with phpmyadmin or put echo mysql_error(); – Ghostman Dec 16 '12 at 17:36

2 Answers2

0

require_once 'connectbd.php';

Are you sure that is not:

require_once 'connectdb.php';

Try using Single Quotes instead inside your mysql query:

$result = mysql_query("SELECT username from ocbup_users WHERE username = '".$username."'");

Aditya M P
  • 5,127
  • 7
  • 41
  • 72
0

print out the contents of mysql_error() to see what went wrong. Do this immediately after mysql_query(). Example:

$sql = "SELECT COUNT(*) FROM ocbup_users WHERE username='$user' AND passw='$passw' ";
$res = mysql_query($sql); 
if (!$res) die("FAIL: $sql <br/>" . mysql_error());

You might also want to use a LIMIT clause. If you're new to PHP and MySQL this book will help you get started faster. http://www.sitepoint.com/books/phpmysql5/

Best, ~Ray

Ray Paseur
  • 2,106
  • 2
  • 13
  • 18