Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sounds like you're trying to let users know whether a username or email already exists at registration time. Here's what you can do:</p> <pre><code>&lt;?php //---------------------------------------- // Create first query $usernameQuery = 'SELECT username FROM users WHERE username="'.mysql_real_escape_string($username).'"'; //---------------------------------------- // Query db $usernameResult = mysql_query($userNameQuery); //---------------------------------------- // Check if result is empty if(mysql_num_rows($usernameResult) &gt; 0){ //---------------------------------------- // Username already exists $error[] = 'Username already exists'; //---------------------------------------- // Return error to user and stop execution // of additional queries/code } else { //---------------------------------------- // Check if email exists //---------------------------------------- // Create query $emailQuery = 'SELECT email FROM users WHERE email="'.mysql_real_escape_string($email).'"'; //---------------------------------------- // Query the db $emailResult = mysql_query($emailQuery); //---------------------------------------- // Check if the result is empty if(mysql_num_rows($emailResult) &gt; 0){ //---------------------------------------- // Email already exists $error[] = 'Email already exists'; //---------------------------------------- // Return error to user and stop execution // of additional queries/code } else { //---------------------------------------- // Continue with registration... } } ?&gt; </code></pre> <p>Please note that you should always escape your values before executing the actual query.</p> <p>Additional Resources:<br /> <a href="http://us.php.net/manual/en/function.mysql-real-escape-string.php" rel="nofollow">http://us.php.net/manual/en/function.mysql-real-escape-string.php</a> http://us.php.net/manual/en/function.mysql-escape-string.php</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload