signup.php
<?php
signup.php
include 'connect.php';
include 'header.php';
echo '<h3>REGISTRO</h3>'.$_SERVER['REMOTE_ADDR'];
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo '<form method="post" action="">
Usuario: <input type="text" name="user_name" /><br>
Clave: <input type="password" name="user_pass"><br>
Clave: <input type="password" name="user_pass_check"><br>
E-mail: <input type="email" name="user_email"><br>
<input type="submit" value="REGISTRAR" />
</form>';
}
else
{
/* so, the form has been posted, we'll process the data in three steps:
1. Check the data
2. Let the user refill the wrong fields (if necessary)
3. Save the data
- /
$errors = array(); /* declare the array for later use */
if(isset($_POST['user_name']))
{
the user name exists
if(!ctype_alnum($_POST['user_name']))
{
$errors[] = 'The username can only contain letters and digits.';
}
if(strlen($_POST['user_name']) > 30)
{
$errors[] = 'The username cannot be longer than 30 characters.';
}
}
else
{
$errors[] = 'The username field must not be empty.';
}
if(isset($_POST['user_pass']))
{
if($_POST['user_pass'] != $_POST['user_pass_check'])
{
$errors[] = 'The two passwords did not match.';
}
}
else
{
$errors[] = 'The password field cannot be empty.';
}
if(!empty($errors)) /*check for an empty array, if there are errors, they're in this array (note the ! operator)*/
{
echo 'Uh-oh.. a couple of fields are not filled in correctly..';
echo '<ul>';
foreach($errors as $key => $value) /* walk through the array so all the errors get displayed */
{
echo '<li>' . $value . '</li>'; /* this generates a nice error list */
}
echo '</ul>';
}
else
{
$sql = "INSERT INTO
users(player, password, motd, email , ip, online)
VALUES('" . mysql_real_escape_string($_POST['user_name']) . "',
'" . mysql_real_escape_string($_POST['user_pass']) . "',
'&aWelcome Back PLAYER \n&bWe Missed You!',
'" . mysql_real_escape_string($_POST['user_email']) . "',
'" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "',
0)";
$result = mysql_query($sql);
if(!$result)
{
echo 'Something went wrong while registering. Please try again later.';
}
else
{
echo 'Successfully registered. You can now <a href="signin.php">sign in</a> and start posting! :-)';
}
}
}
include 'footer.php';
?>
Comments