Look @ AJAX, i.e. create a php function that will return a boolean of true or false if a given variable is passed to it
The mentioned function is what will check for the value in the database
If you are trying to avoid screen refreshes and do everything interactively, then this obviously isn't the right solution but I thought that I'd show you this approach so you understand the options.
[I'm having a problem with Markdown so I left this as plain text. Need to do some experimenting!]