0

I want make function that check whether specific data is in mydb in mysql. I wrote below function but I get error this line $is_ok_array=mysql_fetch_row($is_ok); Can Someone help me? Sorry my bad English :)

It says: mysql_fetch_row() expects parameter. I searched that error express that my sql doesn't work properly. But my sql query is working. Here is

$query_add ="INSERT INTO notes1 (id,name,size,url,thumbnail_url,delete_url,delete_type)    VALUES('$_SESSION[userid]','$file_name','$file_size','$file_url','$file_thumbnail_url','$delete_url','$delete_type')";

-- My Function

protected function is_same($file_name,$file_size,$file_url,$file_thumbnail_url,$delete_url1,$delete_type1) {

    $query_same = "Select * From notes1 WHERE id='$_SESSION[userid]' and name='$file_name' and size='$file_size' and url='$file_url' and thumbnail_url='$file_thumbnail_url' and      delete_url='$delete_url1' and delete_type='$delete_type1'" or die (mysql_error());
    $is_ok = mysqli_query($this->is_db_open,$query_same);   

    if($is_ok) {
        $is_ok_array = mysql_fetch_row($is_ok);
    } else { 
        echo "Wrong query";
    }

    if($this->is_db_open) {

        echo count($is_ok_array);

        if((count($is_ok_array))>0) { 
            return true;
        } else {    
            return false;
        }

    } else {
        echo "Db not open";
    }
}

4 Answers 4

3

You have 2 problems with your code, the first is:

$is_ok= mysqli_query($this->is_db_open,$query_same); 

Based on the fact that you're using it in an if statement later in the code and the naming, it seems like $this->is_db_open is a boolean indicating if you have a connection to the database or not, rather than the connection object returned from mysqli_connect().

mysqli_query() expects the first parameter to either be the connection object, or the query if there is no second parameter. Either remove the $this->is_db_open parameter and it will default to the most recently opened database connection, or replace it with the actual connection object.

Your second problem is that you are running the query with mysqli_query() and returning the result with mysql_fetch_row(). You need to use mysqli_fetch_row() to match your query function.

Sign up to request clarification or add additional context in comments.

Comments

1

you are using a mysqli_* query

mysqli_query($this->is_db_open,$query_same);
     ^

but then using a mysql_* fetch

mysql_fetch_row($is_ok);

try using the mysqli_ fetch_row

mysqli_fetch_row($is_ok);
     ^

Comments

1

You can't use mysqli_query result with mysql_ functions. Apparently, you want to use mysql_query. Also, just in case, ensure that you've connected to mysql beforehand.

Comments

1

You are using mysql_fetch_row() to fetch the results of a query. However mysql_fetch_row() has been deprecated. Read this: http://php.net/manual/en/function.mysql-fetch-row.php

Please use mysqli_fetch_row() to get the results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.