Checking whether a record exists

Results 1 to 2 of 2

Thread: Checking whether a record exists

  1. #1
    Join Date
    Dec 1969

    Default Checking whether a record exists

    Hi,<BR><BR>I&#039;ve got a query which returns all the products within a category. Is there a good way to have the database report that a category doesn&#039;t even exist so that I can choose a default category should someone alter the query string which contains the category ID?<BR><BR>I.

  2. #2
    Join Date
    Dec 1969

    Default Do you have separate categories table?

    Do you have a separate table just for the categories?<BR><BR>If so, you could of course first make a query against that table and, if you get EOF, then the user mucked with the category ID.<BR><BR>But you could also then use an OUTER join to do it all in one query:<BR><BR>SELECT * FROM Categories AS C LEFT JOIN Products AS P<BR>ON P.catID = C.catID WHERE C.catID = ###<BR><BR>If you get an EOF from that, then the user messed with the category number. If, however, you get one record but that record has NULLs for all the Products fields, then it means the category is valid but there aren&#039;t any products in that category yet.<BR><BR>Of course, one easy thing to do would be to stop using query strings and use &#060;FORM METHOD=POST&#062; instead. Then the only way for somebody to "spoof" you would be to purposely go into your HTML code and muck with it. And if you checked HTTP_REFERER, too, then the only way would be to use a browser-spoofer.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts