I've looked around the boards but there are no complete answers that I could find. I'm using PHP and MySQL to create and manage a volunteer sign up form.
I need to make sure that there are no duplicate email addresses (email key is UNIQUE)
Here is the code I'm working with, however I need help with understanding where to put the function as I'm also using check_input to strip slashes etc.
The results are that the test entries using a duplicate email don't post to the database, however on the process page it still gives the user their confirmation instead of an error.
The following code is on the process.php page, after the DB connection PHP and INSERT code:
<?php
function createUser($email)
{
$sql = "SELECT * FROM vols2012 WHERE email='$email'" ;
$result = mysql_query( $sql ) ;
if( mysql_num_rows( $result ) > 0 )
{
die( "There is already a user with that email!" ) ;
}//end if
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
}
?>