Click to See Complete Forum and Search --> : [RESOLVED] problem with user registration


roondog
06-14-2007, 02:16 PM
here is the code i'm using


<?php
$page_title = 'Register';
include ('./header.html');
if (isset($_POST['submitted'])) {
require_once ('./mysql_connect.php');
if (eregi ('^[[:alpha:]\.\' \-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
$fn = escape_data($_POST['first_name']);
} else {
$fn = FALSE;
echo '<p><font color="red" size="+1">Please enter your first name!</font></p>';
}
if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
$fn = escape_data($_POST['last_name']);
} else {
$fn = FALSE;
echo '<p><font color="red" size="+1">Please enter your last name!</font></p>';
}
if (eregi ('^[[:alnum:] \f\r\t\n\v]{2,20}$', stripslashes(trim($_POST['gamertag'])))) {
$g = escape_data($_POST['gamertag']);
} else {
$g = FALSE;
echo '<p><font color="red" size="+1">Please enter your gamertag!</font></p>';
}
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST ['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid e-mail address!</font></p>';
}
if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST ['password1'])))) {
if ($_POST['password1'] == $_POST
['password2']) {
$p = escape_data($_POST ['password1']);
} else {
$p = FALSE;
echo '<p><font color="red" size="+1">Your password did not match the confirmed password!</font></p>';
}
if ($fn && $ln && $g && $e && $p) {
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_num_rows($result) == 0) {
$a = md5(uniqid(rand(), true));
$query = "INSERT INTO users (email, pass, first_name, last_name, gamertag, active, registration_date) Values
('$e', SHA('$p'), '$fn', '$ln', '$g', '$a', NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
}
if (mysql_affected_rows() == 1) {
$body = "Thankyou for registering at this site. To activate your account, please click on this link:\n\n";
$body = "http://www.place.com/activate.php/x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body);
echo 'nice one!';
include ('./footer.html');
exit();

} else {
echo 'you have not been registered sorry';
}
} else {
echo 'that address has already been registered.';
}
} else {
echo 'please try again';
}
mysql_close();
}
?>
<form action="register.php" method="post">
<fieldset>
<p>First Name:<input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name:<input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Gamertag:<input type="text" name="gamertag" size="15" maxlength="15" value="<?php if (isset($_POST['gamertag'])) echo $_POST['gamertag']; ?>" /></p>
<p>E-mail:<input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>password:<input type="password" name="password1" size="20" maxlength="20" />Use only letters and numbers. Must be between 4 and 20 characters.</p>
<p>Confirm password:<input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
<div align="center"><input type="submit" value="Register" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./footer.html');
?>


the problem i keep getting is that it says the e-mail is already used but there is nothing in the database.

tca
06-14-2007, 07:38 PM
I'm not too good at regular expressions but your code is so similar to the code I use I think it might be that your eregi is returning a blank email, thus it matches the nothing in the database.

This is just a shot in the dark mind you, but try this:

if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {


The period here _.- is not escaped in my version.

TC

andre4s_y
06-14-2007, 10:16 PM
Sorry, i newbie,
what is the main function of escape_data() function??
n

if ($fn && $ln && $g && $e && $p) {

little strange there....
what happen if somebody have the name : false???
Andre

roondog
06-15-2007, 03:27 AM
Still not working. Its frustrating as I copied it from a book just adding the bit for the gamertag. In theory it should work.

roondog
06-15-2007, 04:06 AM
Found the problem i was using $fn for the last name. changed it to $ln and it works. 3 days its taken me to get this to work after various problems. Now tot he next script.