views:

96

answers:

1

Hey I'm really new to PHP and PostgreSQP or any database in that matter. So I'm at a loss how to do this.

I need an if statement that says.

If(the username user just typed in is already in database) {
  my code here
}

the variable the username that the user just typed in is $userNameSignup

how would I do that with PHP for PostgreSQL?

also how might I redirect people to a new page once they have completed the form properly?

Thanks Shelby

A: 
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);

    $result = pg_query('SELECT 1 FROM logins WHERE LOWER(userName)=\''.strtolower(pg_escape_string($userNameSignup)).'\'') or exit(pg_last_error());

    if (pg_num_rows($result)) {

        $userNameSignupError = 'Username already taken please choose a new one.';
    }

finally figured it out ^.^

MrEnder
You are much better off using $result = pg_query_params('SELECT 1 FROM logins WHERE lower(username)=$1', array($userNameSignup)) It'll be both faster and less subject to small mistakes causing security problems.
Magnus Hagander
I tried that and it doesn't seem to work possibly I used it wrong...
MrEnder
Additionally, I would strongly recommend you look into PDO: http://php.net/pdo
Jordan S. Jones