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
https://forums.phpfreaks.com/topic/77740-solved-weird/
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
https://forums.phpfreaks.com/topic/77740-solved-weird/#findComment-393510
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
https://forums.phpfreaks.com/topic/77740-solved-weird/#findComment-393515
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.