1

Possible Duplicate:
Why do I get “Resource id #4” when I apply print_r() to an array in PHP?
How do i “echo” a “Resource id #6” from a MySql response in PHP?

why do i get "Resource id #6" as result in $result? want 1 or 0 :P

$sql = "SELECT * FROM members WHERE rchat=1 LIMIT 1";
$result = mysql_query($sql);

if (!$result) {
unlink($fn);
//$fn = $_SESSION['sess_user'].'.txt';
$fn = 'hittaingen.txt';
mysql_query("UPDATE members SET rchat=1 room='" . $_SESSION['sess_user'] . "' WHERE     user='" . $_SESSION['sess_user'] . "'");
}

else {
  //$fn = $result['room'].'.txt';
  $fn = 'hitta.txt';
  mysql_query("UPDATE members SET rchat=2 room='" . $result['room'] . "' WHERE user='" . $_SESSION['sess_user'] . "'");
  }
Community
  • 1
  • 1

1 Answers1

2

mysql_query() returns just a reference of the result object and not the result itself. So in order to get you 0 or 1, you got to parse the result first using, e.g., mysql_fetch_array()

$row = mysql_fetch_array( $result );

Besides, you should definitely look into PDO and mysqli, as the the mysql_X() functions are marked as deprecated and generally not considered safe against SQL injections!

Thilo
  • 17,565
  • 5
  • 68
  • 84
Sirko
  • 72,589
  • 19
  • 149
  • 183