The Database class has a nice feature to escape your query for you. I haven't tested so tell me if it breaks.
include('include/Database.inc.php');
// say you get $tablename and $first_name from $_POST array
// make sure they are set first. if not die and tell the user why
$sql = "SELECT * FROM %s WHERE first_name = '%s';";
$r = $db->q($sql, array($tablename, $first_name));
// now do whatever you need to with result
That should get you started. See ajax.php for more.
Secondly, I think these can actually be included in the top of the form files by using require_once('include/submit-grower.php') and such. This will perform the checks and print the message on the current page. First fix the $db issue, then we can look at including it.
The Database class has a nice feature to escape your query for you. I haven't tested so tell me if it breaks.
That should get you started. See ajax.php for more.
Secondly, I think these can actually be included in the top of the form files by using
require_once('include/submit-grower.php')
and such. This will perform the checks and print the message on the current page. First fix the $db issue, then we can look at including it.