0

I'm getting this error message: "Mysql_fetch_array supplied argument is not a valid MYSQL result" but I don't know whats wrong with the code

$sql = "SELECT *, status_pedido.nome as descricao_status,frete.nome as nome_frete, historico.data as data_hist, DATE_FORMAT(historico.`data`,'%d/%m/%Y') as data, DATE_FORMAT(historico.`data`,'%H:%i:%s ') as hora
                    FROM midiosto_db.`l-pedidos` as pedido
                    INNER JOIN midiosto_db.`l-pedido-historico` as historico
                        ON pedido.id = historico.`id-pedido`
                    INNER JOIN midiosto_db.`l-status` as status_pedido
                        ON status_pedido.id = historico.`id-status`
                    INNER JOIN midiosto_db.`l-frete` as frete
                        On frete.id = pedido.`id-frete`
                    WHERE pedido.id  = ".$_GET["id_pedido"]."
                    ORDER BY data_hist DESC";

$query_historico = mysql_query($sql);
$row_historico = mysql_fetch_array($query_historico);
AND4011002849
  • 1,971
  • 8
  • 38
  • 81
  • 2
    First change `mysql_query($sql);` to `mysql_query($sql) or die(mysql_error());` and see if you get an error. – naththedeveloper Mar 06 '14 at 13:58
  • 2
    Also note that `mysql_` functions should no longer be used. Use `mysqli_` or PDO. – naththedeveloper Mar 06 '14 at 13:58
  • 3
    **Before you post a question asking "What does this error message mean?" do a search in the search box for the actual error message.** There you will find other questions from people who have had the exact same problem, and then you can learn how they solved it. – Andy Lester Mar 06 '14 at 13:59
  • did you put 'or die' behind the mysql_query($sql) as well? – Lexib0y Mar 06 '14 at 14:04
  • @FDL I got SELECT command denied to user 'midiosto_sys'@'localhost' for table 'l-pedidos' – AND4011002849 Mar 06 '14 at 14:05

1 Answers1

1

Be careful to SQL inection with this code... get is no secure at all. Use PDO instead mysql_query.

And for your error message, query_historico is probably not of the type you expect because your SQL statement is maybe wrong.

Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54