Try to break down your problem into several parts.
1) Make a serverside script to query your database, using a string obtained to the script via GET/POST
2) Make changes to the above program such that it can return a 1/true or 0/false based on the success/failure of the DB query
3) Make a jQuery script to send Ajax requests to above made serverside script, along with the user's input.
4) Catch the return value from the script and show adequate messages/hints to the user.