Check if record exists in a table

I have a recipe table where the user will be able to add and delete records.
The user will enter the record number he wants to delete in a numeric field and then hit a delete button.
I need to check if the record exists before I delete it from the table.
I want to do the same for the addition of a record in the table. I want to check if the record exists in the table before I add it again.

What sort of mySQL query do I need to add to the button to return a boolean result that indicates if the record exists or not??

system.db.runScalarQuery() will return the value from the first row and column of a query. Ideally, you’d make your query to return just one row and column. :slight_smile:

[code]query=“SELECT COUNT(*) from table where id=’%s’”
recordExists=system.db.runScalarQuery(query % (str(recordId)))
if recordExists: # or, if recordExists > 0:
do something
else:
do something else

[/code]