0

we're trying to check if a token which has been generated earlier is available in our Database, however we're getting the Error code "Resource ID #6" when we try to extract a matching database entry from the database.

Here's a snippet of our code:

$key= $_GET['token'];
$keytest = mysql_query("SELECT * FROM tokens WHERE token = '$key'");

Thanks in advance.

1 Answers1

1

Well, first of all, you should not be using mysql_* extension because it is deprecated. You're also vulnerable to SQL injection because you're not escaping your inputs.

Regarding about Resource id #4, it is a resource returned by your mysql_query() call, not an actual row object/array (source).

If you want to get an object/array, you need to add an additional line:

$keytest = mysql_fetch_array($keytest);

Now your $keytest is an object/array (array more likely). To get value from this array, you need to specify array's key. For example, if you have a column called unique_id, then you can echo it by writing something like:

echo 'Token unique ID: '.$keytest['unique_id'];

That's it about how to retrieve data. But as I have said earlier, you should not use mysql_*, better is to use either prepared statements or mysqli_*.

Community
  • 1
  • 1
Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54