Jump to content


Photo

Registration Problem


  • Please log in to reply
12 replies to this topic

#1 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 02:28 AM

Hey, I've got a problem with my code that I can't figure out. The following code is at the top of my php page before the <html> line.

<?php
$error = '';

/* make database connection */
$db = mysql_connect ('*********','********','********');
mysql_select_db ('********',$db);

if (isset($_POST["username"])) {
	// Get Values
	$username = $_POST["username"];
	$password = $_POST["password"];
	$password2 = $_POST["password2"];
	$email = $_POST["email"];
	$email2 = $_POST["email2"];
	$location = $_POST["location"];
	$bd = $_POST["bd"];
	$bm = $_POST["bm"];
	$by = $_POST["by"];
	$gender = $_POST["gender"];
	$homepage = $_POST["homepage"];
	
	// Make sure fields are filled out	
	if($username=NULL|$password=NULL|$password2=NULL|$email=NULL|$email2=NULL) {
		$error = 'A required field was left blank.';
	} else {
		// Passwords Match
		if($password!=$password2) {
			$error = "Passwords don't Match.";
		} else {
		// Emails Match
		if ($email!=$email2) {
			$error = "Email's don't Match.";
		} else {
		// Has Username Been Used
		$checkuser = mysql_query("SELECT name FROM user WHERE name='$username'");
		$user_exists = mysql_num_rows($checkuser);
		if($user_exists>0) {
			$error = "Username already in use.";
		} else {
		$checkemail = mysql_query("SELECT email FROM user WHERE email='$email'");
		$email_exists = mysql_num_rows($checkemail);
		if ($email_exists>0) {
			$error = "A user is already registered with that email.";
		} else {
			$password = md5($password);
			$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .  								   						"'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
			mysql_query($query) or die(mysql_error());
			$registered = 1;
		}
	}
}
?>

The error I get is "Parse error: parse error, unexpected $ in ****** on line 451"

Line 451 is the </html> (end of document)

- Thanx

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 08 August 2006 - 02:32 AM

Take a look at
$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .

Btw.. Change | to ||

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 02:38 AM

Don't know why it pasted like that, but in the actual thing it's like this:

$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .						   						
	"'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";

I also changed | to ||, but no luck.

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 08 August 2006 - 02:42 AM

Hmm.. Use elseif..
Edit:
Change = to ==

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 02:45 AM

Would that really make a difference though?

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 08 August 2006 - 02:47 AM

Your elseif is wrong, its in a mess..
Also, = and == is totally different.

if($username==NULL||$password==NULL||$password2==NULL||$email==NULL||$email2==NULL) {


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#7 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 02:49 AM

Your elseif is wrong, its in a mess..
Also, = and == is totally different.

if($username==NULL||$password==NULL||$password2==NULL||$email==NULL||$email2==NULL) {


Yeah I changed that line with the == and || and still got the same error.

As for the else/elseif I'll try that now.

EDIT: Still no luck. This is what I have now, anything missing?

<?php
$error = "";
$registered = 0;

/* make database connection */
$db = mysql_connect ('*********','********','********');
mysql_select_db ('********',$db);

if (isset($_POST["username"])) {
	// Get Values
	$username = $_POST["username"];
	$password = $_POST["password"];
	$password2 = $_POST["password2"];
	$email = $_POST["email"];
	$email2 = $_POST["email2"];
	$location = $_POST["location"];
	$bd = $_POST["bd"];
	$bm = $_POST["bm"];
	$by = $_POST["by"];
	$gender = $_POST["gender"];
	$homepage = $_POST["homepage"];
	
	// Make sure fields are filled out	
	if($username==NULL||$password==NULL||$password2==NULL||$email==NULL||$email2==NULL) {
		$error = 'A required field was left blank.';
	// Passwords Match
	} elseif($password!=$password2) {
		$error = "Passwords don't Match.";
	// Emails Match
	} elseif ($email!=$email2) {
			$error = "Email's don't Match.";
	// Emails Match
	} else {
		$checkuser = mysql_query("SELECT name FROM user WHERE name='$username'");
		$user_exists = mysql_num_rows($checkuser);
		if($user_exists>0) {
			$error = "Username already in use.";
		} else {
		$checkemail = mysql_query("SELECT email FROM user WHERE email='$email'");
		$email_exists = mysql_num_rows($checkemail);
		if ($email_exists>0) {
			$error = "A user is already registered with that email.";
		} else {
			$password = md5($password);
			$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .						   						"'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
			mysql_query($query) or die(mysql_error());
			$registered = 1;
		}
	}
}
?>


#8 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 08 August 2006 - 03:07 AM

You short of one more }

Edit:
Make your life easier :P
else {
		$checkemail = mysql_query("SELECT email FROM user WHERE email='$email'");
		$email_exists = mysql_num_rows($checkemail);


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#9 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 03:11 AM

Wow. All that and it was a simple }. Thanx for your help.

#10 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 08 August 2006 - 03:13 AM

Your welcome, if you have any more problems feel free to ask. :)
Cheers~

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#11 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 03:40 AM

I've got another problem, felt I could just post it here.

I'm getting a MySQL error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES('a', '0cc175b9c0f1b6a831c399e269772661', 'a', '', 'Undisclosed', '', ' at line 1

With this code:

$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username', '$password', '$email', '$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
				mysql_query($query) or die(mysql_error());


#12 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 08 August 2006 - 04:06 AM

Try changing the field name from by to something like author. Then post if you are still getting the error.

You can still use $by but change the field in the database to something else

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#13 MadDawgX

MadDawgX
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 August 2006 - 04:12 AM

Okay, thanx. That worked.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users