Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem lies with the SQL to check for duplicate usernames.</p> <pre><code>// Check for existing username $sql = "SELECT * FROM `members`"; $result2=mysql_query($sql); while($row=mysql_fetch_array($result2)){ $username2 = $row['username']; ... }} </code></pre> <p>I have taken your code, and made some minor changes. I have changed your SQL query to retrieve a count of users with the same username, instead of returning every username to check individually.</p> <p>I have also taken the code around the <code>mail()</code> function out of a loop. If no duplicate usernames have been found, the <code>$duplicateUsername</code> variable is set to false, otherwise its set to true.</p> <p>If <code>$duplicateUsername</code> is false, then the mail function is called... once, otherwise the error is displayed.</p> <p>Please everything from <code>// Check for existing username</code> with the following:</p> <pre><code>// Check for existing username $username = mysql_real_escape_string($username); $duplicateUsername = false; $sql = "SELECT COUNT(username) AS usernameCount FROM members WHERE username = '{$username}'"; $result2=mysql_query($sql); while($row=mysql_fetch_array($result2)){ $duplicateUsername = $row['usernameCount']&gt;0 ? true : false; } if(!$duplicateUsername){ $sql = "INSERT INTO `members` (`id`, `first_name`, `last_name`, `email`, `username`, `password`, `termsofuse`, `status`, `approved`, `acctype`, `industry`, `newsletter`, `contactnumber`, `hash`, `since`) VALUES (NULL, '$first_name' , '$last_name' , '$email' , '$username' , '$password1' , '$termsofuse', 'Reg', '$approved', '$acctype', '$industry', '$newsletter', '$contactnumber', '$hash', NOW())"; $result = mysql_query($sql) or die ("Can't insert".mysql_error()); $to = $email; // Send email to user $subject = 'Signup Verification'; //Subject line in email $message = 'Welcome ' . $first_name . ',' . "\r\n\r\n" . 'Thanks for signing up!' . "\r\n\r\n" . 'Your account has been created. To activate your account, click on the link below to get started!' . "\r\n\r\n" . 'http://www.radioman911.com/pages/CAD/verify.php?email=' . $email . '&amp;hash=' . $hash . ''; $headers = 'From: xxxx' . "\r\n" . 'Reply-To: same xxxx as above' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers, '-fxxxx same as above'); header("location:new_member_sucess.php"); } else { echo "&lt;style type='text/css'&gt;A{text-decoration:none}&lt;/style&gt;"; echo "&lt;body bgcolor='black'&gt;&lt;font color='white' style='font-family:trebuchet ms;'&gt;"; echo "Passwords do not match or that username is already taken, please try again!&lt;br&gt;"; echo "&lt;a href='javascript: history.go(-1)'&gt;&lt;font color='red'&gt;Go back&lt;/a&gt;&lt;/font&gt;"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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