[PHP] Register page..

Skilled Illusionist
Joined
Aug 18, 2005
Messages
305
Reaction score
78
Hey guys, I dont really good lots of PHP experience but im trying to make a register page, i followed tutorials etc, this is what I got now it doesnt seem to work really work, it says \par all over the screen, would love to get some help here..


do_reg.php
<?php
$host = "localhost"
$dbuser = "root"
$dbpass = "root"
$dbname = "ao"

$connection = mysql_connect($host,$dbuser,$dbpass)
$db = mysql_select_db($dbname,$connection);



$name = $_POST[Username];
$pass = $_POST[Password];
$pass2 = $_POST[Password2];


if($name == false || $pass == false || $pass2 == false}[
echo "Please fill in all the required fields.";
};
if($pass != $pass2)(
echo "Passwords do not match.";
}elsif {
$db = mysql_select_db($dbname, $connection);
$sql = "INSERT INTO login (Username.Password,Allowed_Characters,Flags) VALUES ($name, $pass)";
$result = mysql_query($sql);
echo "Your account has been registered.";

}]
?>

register.php
<?php
$IP = $_SERVER[REMOTE_ADDR];
?>

<form name=reg action=do_reg.php method=post>
Username: <input type=text name=name><br>
Password: <input type=password name=pass><br>
Confirm: <input type=password2 name=pass2><br>
<br>
<input type=submit value='Register'>
</form>
 
Re: PHP Register page..

Cheers, I didnt even notice... but that fixed the \par thing but now when I make a acc I get:

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\register\do_reg.php on line 3
 
Re: PHP Register page..

Well I tried remove em, and add em, but it keeps saying Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\register\do_reg.php on line 3 :-\ and line 3 is $dbuser = "root" wich is pretty much right I think
 
Wow, what a huge mess! Try to clear it up mate, alot of syntax errors in there:

if($name == false || $pass == false || $pass2 == false) // you closed with a }, which is very unlogic as you started with (

$pass2 = $_POST['Password2']; // quotes needed here

$host = "localhost"; // PHP requires lines to always end with ;!

} // except for opening or closing brackets, neither for statements (if, while etc)

INSERT INTO login (Username, Password ... // the dot should be a comma

} elseif { // its elseif, not elsif

} // no ] bracket needed

$IP = $_SERVER['REMOTE_ADDR']; // quotes!

Really, check the code before posting...and read the errors. They're so obvious.
 
Personally, I would write that like:

PHP:
<?php
$MySQL_Host 		= 'localhost'; 	// Server host
$MySQL_DbPort	= '3306';		// Default MySQL Port
$MySQL_DbUser 	= 'root';		// DB Username
$MySQL_DbPass	= 'root';		// DB Password
$MySQL_DbName	= 'ao';			// Database Name
$DBG			= false;			// Debug.

$Con = @mysql_connect("{$MySQL_Host}:{$MySQL_DbPort}", $MySQL_DbUser, $MySQL_DbPass);
	if (!$Con) {
		if ($DBG) {
			die(mysql_error());
		}
		die("<b>ERROR: Could not establish a database connection!</b><br />");
	}
$DB = @mysql_select_db($MySQL_DbName, $Con);
	if (!$DB) {
		if ($DBG) {
			die(mysql_error());
		}
		die("<b>ERROR: Could not select a database!</b><br />");
	}

$Username = $_POST['Username'];
$Password = $_POST['Password'];
$PassConf = $_POST['Password2'];
if (get_magic_quotes_gpc()) {
	$Username = stripslashes($Username);
	$Password = stripslashes($Password);
	$PassConf = stripslashes($PassConf);
}
$Username = mysql_real_escape_string($Username, $Con);
$Password = mysql_real_escape_string($Password, $Con);
$PassConf = mysql_real_escape_string($PassConf, $Con);

if (!empty($Username) && !empty($Password) && !empty($PassConf)) {
	if ($Password == $PassConf) {
		$sql = @mysql_query("INSERT INTO `login` (`Username`, `Password`, `Allowed_Character`, `Flags`) VALUES ('{$Username}', '{$Password}')");
		if (!$sql) {
			if ($DBG) {
				die(mysql_error());
			}
			echo "<b>There was an error registering your account!</b><br />";
		} else {
			$Check = mysql_select("SELECT `Username` FROM `login` WHERE `Username` = '{$Username}'");
			if (mysql_num_rows($Check) >= 1) {
				echo "Your account has been registered.";
			} else {
				echo "There was a problem registering your account.";
			}
		}
	} else {
		echo "Passwords did not match!";
	}
} else {
	echo "You left one or more fields blank!";
}
?>

Edit: To comment on some of your code:
PHP:
$_POST[Username];

For instance should be:

PHP:
$_POST['Username']; // Or $_POST["Username"];

or PHP is going to look for a constant Username, which is not there.

Also, I would look into securing the data you take in some, I my self never take in data directly from post / get or what not and then stick it in the database.

; does not need to follow brackets ( }; ). I am not sure what told you to do that, but I have never seen it?

Checking if $Name == false will generate an E_NOTICE level error (Which will, by default, not be displayed, but its still not good to have imo). I would use empty() instead (See: PHP: empty - Manual for more), as far as I know it does not generate an E_NOTICE error.

I would use else instead of elseif.

Edit again..:

Code:
<?php
$IP = $_SERVER[REMOTE_ADDR];
?>

<form name=reg action=do_reg.php method=post>
Username: <input type=text name=name><br>
Password: <input type=password name=pass><br>
Confirm: <input type=password2 name=pass2><br>
<br>
<input type=submit value='Register'>
</form>

As stated above,
PHP:
$_SERVER[REMOTE_ADDR]; // Should be $_SERVER["REMOVE_ADDR"] or PHP will look for a constant REMOTE_ADDR.

Also, I would put " " around your HTML attribute values (AKA <form method="post" etc..>).
 
Back