9 Replies - 776 Views - Last Post: 01 August 2008 - 07:07 PM Rate Topic: -----

#1 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Problems with duplicate registration

Posted 01 August 2008 - 09:48 AM

On the previous post I had a problem with the login, yet now I have a problem with the registration. It works correctly, except that when you attempt to register with the same username as someone else it says "Your username and password have been registered." It does not duplicate, yet it still says that it has been registered. Here is the code (with the db information removed):

<?
//db information
$conn = mysql_connect(--------);
mysql_select_db(----------, $conn);

if($_POST['submit']){

$username = $_POST['username'];
$password = $_POST['password'];

if(!$username OR !$password){
echo("Error: Please enter a correct username and password.");

}
else 
{
$query = mysql_query("INSERT INTO users VALUES('','$username','$password')");
echo("Your username and password has been registered.");
}
}

else
{
?>

<form method="POST" action="">
Username:<input type="text" name="username"><br>
Password:<input type="password" name="password"><br>
<input type="submit" name="submit" value="Sign Up!">

<?
}

?>



Is This A Good Question/Topic? 0
  • +

Replies To: Problems with duplicate registration

#2 Moonbat  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 424
  • Joined: 30-June 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 09:52 AM

You could just use another elseif combo to see if the value of $_POST['username'] already exists in the DB.

PSUEDO-CODE
SEARCH_DB_FOR $_POST['username']
IF THERE IS A MATCH
   ECHO USERNAME TAKEN
ELSE
   DO SOMETHING ELSE

Was This Post Helpful? 0
  • +
  • -

#3 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 09:54 AM

Then the full code would result as what?
Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 10:47 AM

we're not going to "give" you the code, but we'll tell you how it should look...

you need to query the database for that username and check if it exists... if it does, then tell them they can't choose that name... if it doesn't, then they can have the name...
Was This Post Helpful? 0
  • +
  • -

#5 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 11:59 AM

I was told by someone else to try this (as an edit to the previous code) - yet it seems that when you load the page, I receive an error that is the following: Parse error: syntax error, unexpected T_ELSEIF in /home2/advanco9/public_html/spomi/register1/register11.php on line 31

<?
//db information
$conn = mysql_connect(------);
mysql_select_db(--------, $conn);

if($_POST['submit']){

$username = $_POST['username'];
$password = $_POST['password'];

if(!$username OR !$password){
echo("Error: Please enter a correct username and password.");

}
}
else 
{

	try
 	{
		$query = mysql_query("INSERT INTO users VALUES('','$username','$password')");
		echo("Your username and password has been registered.");
	}
//catch exception
catch(Exception $e)
 {
	 echo 'Message: ' .$e->getMessage();
 }

}
else {
?>

	<form method="POST" action="">
	Username:<input type="text" name="username"><br>
	Password:<input type="password" name="password"><br>
	<input type="submit" name="submit" value="Sign Up!">
	</form>
	<?php
	}
	?>



The error is addressing the else statement near the end.
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1155
  • View blog
  • Posts: 7,167
  • Joined: 07-September 06

Re: Problems with duplicate registration

Posted 01 August 2008 - 03:54 PM

The problem is because you have 2 else statements directly after one another. You will need to get the top one to either be an else if statement or add an if statement before the bottom else statement so that it can do what it is supposed to.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#7 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 04:30 PM

I changed the first else statement to elseif yet it seems I am recieving an error that states the following:

Parse error: syntax error, unexpected '{', expecting '(' in /home2/advanco9/public_html/spomi/register1/register11.php on line 17

It is referencing the beginning bracket after the (changed to) elseif statement.
Was This Post Helpful? 0
  • +
  • -

#8 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 05:24 PM

<?

if($_POST['submit']){

$username = $_POST['username'];
$password = $_POST['password'];

if(!$username OR !$password){
echo("Error: Please enter a correct username and password.");

}

else
{

    try
    {
        $query = mysql_query("INSERT INTO users VALUES('','$username','$password')");
        echo("Your username and password has been registered.");
    }
//catch exception
catch(Exception $e)
{
     echo 'Message: ' .$e->getMessage();
}
}
}
else {
?>

    <form method="POST" action="">
    Username:<input type="text" name="username"><br>
    Password:<input type="password" name="password"><br>
    <input type="submit" name="submit" value="Sign Up!">
    </form>
    <?php
    }
    ?>

Was This Post Helpful? 0
  • +
  • -

#9 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 05:40 PM

It is the same result - the registration works, except it still says that the username has been registered even though it already exists.
Was This Post Helpful? 0
  • +
  • -

#10 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Problems with duplicate registration

Posted 01 August 2008 - 07:07 PM

View PostJBrace1990, on 1 Aug, 2008 - 10:47 AM, said:

we're not going to "give" you the code, but we'll tell you how it should look...

you need to query the database for that username and check if it exists... if it does, then tell them they can't choose that name... if it doesn't, then they can have the name...

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1