You will need to do this using Ajax. I recommend the Jquery library. Install it using the Jquery documentation, and then use something like the following:
Javascript:
function makeAjaxRequest()
{
var url="script-that-checks-db.php";
$.get(url,{},verifyDb);
}
function verifyDb(response)
{
if (response==1)
{
//The value exists, do what you want to do here
}
else
{
//The value doesn't exist
}
}
You can have makeAjaxRequest()
invoked when someone clicks a link, clicks a button, or anything else, e.g:
<a href="#" onclick="makeAjaxRequest();">Check database</a>
The php code of the file script-that-checks-db.php
(of course, name it something different) will be responsible for checking the db. The code would look something like this.
PHP:
<?php
//Do the mysql query and find out if the value exists or not.
if ($exists==true)
echo "1"; //1 will indicate to javascript that the value exists.
else
echo "0";
?>
You could also use JSON here rather than the 0/1 method, but because you are new I think this will be simple enough for you.
Hope this helps, if you have any questions feel free to ask. Also, feel free to change the function and file names.