mysqli_result Object ( )

Asked

Viewed 99 times

4

I’ve spent the last three hours trying to find the error... maybe it’s sleep, but I’ll put my very complicated script so someone can shed some light.

$query_passaporte = "SELECT num_compra, data_compra, plano, passaporte_paypal FROM paypal WHERE 'empid' = ' ".$_SESSION['empid']." ' AND 'show' ='1' ORDER BY num_compra ASC";

$dados_passaporte = mysqli_query($dbc, $query_passaporte) or die(mysqli_error($dbc));

while(list($num_compra, $data_compra, $plano, $passaporte_paypal) = mysqli_fetch_array($dados_passaporte)){

    echo 'nao funciona'.$num_compra. $data_compra. $plano. $passaporte_paypal;} 

    print_r($dados_passaporte); ------> resulta em mysqli_result Object ()  

ECHO does not return.

$dbc is OK. In the query, I use simple quotes in EMPID and SHOW not to give syntax error (do not know pq gives error, other scripts are without quotes)

It was the first code written after I formatted my windows and put UBUNTU (although I’m sure it has nothing to do).

I just don’t know what I’m missing...

  • 2

    Do not use single quotes ' in value-only field names, if you have a special character name or reserve word, use the crase >>`<<

  • 1

    Just for the record: Object () is the expected output for $dados_passaporte. Your data is actually in mysqli_fetch_array($dados_passaporte).

1 answer

4

Do not use single quotes ' in field names only for values, if you have a special character name or reserved word use the crase ` ("show" is a mysql reserved word).

Your consultation should look like this:

$query_passaporte = "SELECT num_compra, data_compra, plano, passaporte_paypal
FROM paypal WHERE empid = ' ".$_SESSION['empid']." ' 
AND `show` ='1' ORDER BY num_compra ASC";

I recommend using Prepared staments to avoid problems with sql Injection.

  • @bfavaretto, if you know how to make an escape in the crase warns ai.

  • I’m trying to find out. In comments it works to escape with backslash: ```. In posts this does not work.

  • @bfavaretto, the other day answered practically the same thing, this is worth as duplicated?

  • 1

    To escape the backtick: \` ` ``ou<code>&#96;</code>`.

  • There are already other questions with the same problem in reserved words. I do not know if you can consider duplicate no. But it deserved a mention on the wiki of the mysql tag.

  • @bfavaretto, as it is, the context of the question is different but the error is the same as parse, can happen to appear a question this week. thanks for the tip of the exhaust :)

  • 1

    Depending on the context, you can use \ para escapar o _backtick_. Isso aqui: \\\ turned into this: ``` (now imagine to make this comment how much of escape it is necessary :) )

  • Thank you @Bacco :)

  • Opa, thanks for the answer. did not know about this SHOW thing, so I’m going to change the name of the column. That must be what’s giving Zica. Now you left me with another question. Exactly where I should be careful with SQL Injection?

  • @Bacco this works in comments but not in the body of the post.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.