Jump to content

[SOLVED] Weird...


Wolphie

Recommended Posts

Ok so with the following code i'm trying to check the database for already used usernames and e-mail addresses.

I'm not entirely sure if this is working or not, but all i'm getting back is a blank page.

 

function checkDetails()
{
$username 		= mysql_escape_string($_POST['username']);				// Retrieve username from registration form
$email		 		= mysql_escape_string($_POST['email']);						// Retrieve e-mail from registration form

$sql = mysql_query(sprintf("SELECT `username`, `email` FROM `users`")) 
or die('Error: ' . mysql_error());

while($obj = mysql_fetch_object($sql))
{
	if(($obj->username) == $username || ($obj->email) == $email)
	{

		?>

			<table width="500" cellpadding="0" cellspacing="0" class="mainBody" align="center">
				<tr>
					<td align="center" class="headTitle">
						<u>Registration Failed!</u>
					</td>
				</tr>

				<tr>
					<td align="center">
						<p>
							The username or e-mail address you have chosen is currently in use. Please use a different username or e-mail address.
						</p>
					</td>
				</tr>
			</table>

		<?

	}
	else
	{
		checkReg();
	}
}
}

checkDetails();

Link to comment
Share on other sites

Instead of fetching all of your data, just check how many records contain the given user/email:

 

<?php

function checkDetails()
{
$username 		= mysql_escape_string($_POST['username']);				// Retrieve username from registration form
$email		 		= mysql_escape_string($_POST['email']);						// Retrieve e-mail from registration form

$sql = mysql_query(sprintf("SELECT * FROM `users` WHERE username='$username' OR email='$email'")) 
or die('Error: ' . mysql_error());

if(mysql_num_rows($sql) > 0)
	echo "Choose something different!";
}

?>

 

 

Orio.

Link to comment
Share on other sites

    $check = (mysql_fetch_array(mysql_query(
                 "SELECT `email`, `loginName` FROM `users` WHERE loginName='$username' AND email='$email'"))
);

if ($NewUser == $check[1] || $NewEmail == $check[0]) {
    echo 'that username and/or email address is already in use.';
	exit;
}

 

oowwps i posted this seconds after you made it solved^^

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.