I have a form submitting to a database. Before saving the information, I want to run various checks on the data.
How can I check if the data exists in the Database?
This is what I figured out so far, (not complete)...
// Verify if the submitted key exists in table 'fromto' column 'fromto_id'
function VerifyDataFromTo($str)
{
$query = "SELECT fromto_id FROM fromto WHERE fromto_id = $str LIMIT 1";
$query = stripslashes($query);
$result = mysql_query($query) or die("Ouch...");
if (!in_array($str,$result)) {die ("Hey Kiddo, Somethin's wrong");}
}
VerifyDataFromTo($_POST['fromto']);
How can I return a nice error message (instead of the "die" message)?
Thanks for the help...