07-08-2011, 07:56 PM
This is a simple form that allows you to register for lastchaos, fill in the dbuser, dbpass, dbhost and db name and your all set.
also youll want to change the message for welcome to pyrexiastudios lastchaos to your own server name
"
"you should change register2.php to the same page the that the form is on
DEMO: 2
Features
anti sql inject
username limit 15 (like the lastchaos username limit)
password has to be more than 6 characters
all fields must be filled in to register
Working on
No spaces in username
Must have @ and atleast 1 . in your email
updated for 00211
<?php
echo "Register";
$dbuser = "root";
$dbpass = "";
$dbhost = "127.0.0.1";
$dbname = "lcep2";
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_escape_string($str);
}
//form data
$submit = strip_tags(@$_POST [submit]) ;
$username = clean(strip_tags(@$_POST [username])) ;
$password = clean(strip_tags(@$_POST [password])) ;
$repeatpassword = clean(strip_tags(@$_POST [repeatpassword])) ;
$email = strip_tags(@$_POST [email]) ;
$date = date("Y-m-d") ;
if ($submit)
{
//check for existance
if ($username&&$password&&$repeatpassword&&$email)
{
//password match
if ($password==$repeatpassword)
{
//opens database
$msconn = mysql_connect($dbhost, $dbuser, $dbpass);
$db = mysql_select_db($dbname, $msconn);
mysql_query("set names UTF8");
//Check for duplicate login ID
if($username != ) {
$qry = "SELECT * FROM t_users WHERE a_username=$username";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0)
{
echo Username already in use.;
}
else
{
//username and email lengh
if (strlen($username)>15||strlen($email)>30)
{
echo "lengh of Username or Email is too long!";
}
else
{
//check password lengh
if (strlen($password)>15||strlen($password)<6)
{
echo "Password must be between 6 and 15 characters";
}
else
{
//register the user
//open database
$queryreg = mysql_query("INSERT INTO t_users VALUES (,$username,$password,1,0,0,$email,$date,)");
die("You are now registered for PyrexiaStudios LastChaos");
}
}
}
}
}
}
else
echo "Your Passwords do not match!";
}
else
echo "Please fill in all of the fields!";
}
?>
</pre>
<table width="296">
Username:
>
Password:
Repeat Password:
Email:
>
</table>
<br><br><b
[special Thanks to Max for help with anti sql injection]
