-1

I am stuck with the following error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/****/public_html/10minutes8983.php on line 23

and I'm completely lost as to why since I have used this method for getting something from db many times before..

Below is line 23 and 24.

LINE 23:$find = mysql_fetch_array(mysql_query("SELECT user FROM $tab[pimp] WHERE id='$id';"));

LINE 24:$user = mysql_fetch_array(mysql_query("SELECT turbo,platinum,gold,silver FROM $tab[user] WHERE username='$find[0]';"));

Anyone have any ideas about why this is occuring?

Many thanks!

  • 1
    Use PDO instead of mysql_query . Simple and safe – BenB Mar 06 '15 at 22:35
  • 2
    You likely have an SQL injection vulnerability in this code. –  Mar 06 '15 at 22:36
  • There is an error with your SQL. Can you - echo "SELECT user FROM $tab[pimp] WHERE id='$id';"; on the line above and post what it prints? – NaN Mar 06 '15 at 22:36
  • You have a syntax error in your SQL. Split it up into separate statements so you can check the result of `mysql_query()` and do `die(mysql_error())` if it fails. Then you'll see the SQL error message. – Barmar Mar 06 '15 at 22:36
  • I'll do that now Nan. And sorry Barmar, my php level is very basic and self taught. I'm not quite sure how to type what you've suggested! – Harry Sinfield Mar 06 '15 at 23:16

1 Answers1

-1

Try using {} brackets {$tab[pimp]} inside the query string, just like below:

LINE 23: $find = mysql_fetch_array(mysql_query("SELECT user FROM {$tab[pimp]} WHERE id='$id';"));

engine9pw
  • 362
  • 1
  • 5
  • no luck unfortunately! – Harry Sinfield Mar 06 '15 at 23:08
  • Add a debug message before the line 23, only with the query: echo "SELECT user FROM {$tab[pimp]} WHERE id='$id'";exit; If the query looks ok, copy it into an SQL client and run it. PS: Also, ";" is not necessary at the end of the query. – engine9pw Mar 06 '15 at 23:27