checkUnique function?

Posted by Chris Leah on Stack Overflow See other posts from Stack Overflow or by Chris Leah
Published on 2010-04-13T15:58:32Z Indexed on 2010/04/13 16:03 UTC
Read the original article Hit count: 348

Filed under:
|
|

Hey, so I have created a function to check the DB for unique entries, but when I call the function it doesn't seem to work and gives me a fatal error any ideas from the function or do you wish to see the sign up page calling it. Thanks :)

 //Check for unique entries
    function checkUnique($table, $field, $compared)
    {
        $query = $mysqli->query('SELECT  '.$mysqli->real_escape_string($field).' FROM '.$mysqli->real_escape_string($table).' WHERE "'.$mysqli->real_escape_string($field).'" = "'.$mysqli->real_escape_string($compared).'"');
        if(!$query){ 
            return TRUE; 
        }   
        else {
            return FALSE;
        }
    }

The page calling it.....

if (!empty($_POST['username']) && !empty($_POST['password']) && $_POST['password']==$_POST['password_confirm'] && !empty($_POST['email']) && validateEmail($_POST['email']) == TRUE && checkUnqiue('users', 'email', $_POST['email']) == TRUE && checkUnique('users', 'username', $_POST['username']) == TRUE)

© Stack Overflow or respective owner

Related posts about php

Related posts about mysqli