I have a quiz form that is connected to my database, however I need to prevent duplicate email entries being inserted. I have tried the following:
//Check for d
In PHP you can't place a function inside another function. So you need to place it outside your action_myquiz
function. You'll also want to change mysql_result
to mysql_num_rows
. Something like this
//Check for duplicate email addresses
function checkEmail($email){
$sql = DB::select('email')->from('myquiz')->where('email','=',"$email")->execute();
$result = mysql_num_rows(mysql_query($sql),0) ;
if( $result > 0 ){
return true;
}
return false;
}
//Now start your other function
function checkEmail($email){
Then inside your action_myquiz
function you need to call your checkEmail
function. Like
if(checkEmail($email) === false) {
//Proceed with insert
} else {
//Don't do insert
}