First , get rid of the mysql_pconnect, only use it if you have a good reason, and I doubt that you do, because nobody really does 🙂
Second; this never worked:
if (mysql_fetch_array($data)==0)
mysql_fetch_array returns TRUE or FALSE, never zero.
On top of that, you should check for the number of records in the resultset, not for the fact that you could or could not fetch a record. You execute the querym, the fetch all rows from the resultset and then you check to see if it is possible to fetch a row. Obviously once you fetched them all, you can never fetch one more, so this will always fail.