thenewprogrammer
New Member
- Messages
- 45
- Reaction score
- 0
- Points
- 0
Having problems with php registering script, confirm php is file with login information
register.html file
registernext.php file
for some reason it keeps triggering my else statements instead of going to next step. The else statements it triggers is "error" and "Cannot send confirmation link to your email address" so im guessing the error is caused around if($result) but not sure. I need it to be successful and the the two tables i have in database are "temp" and "users"
register.html file
Code:
<form name="form1" method="post" action="registernext.php">
Username:<input type="text" name="username" size="15" maxlength="20" value=""><br />
Password:<input type="password" name="pass" size="15" maxlength="20" value=""><br />
Confirm Password:<input type="password" name="pass2" size="15" maxlength="20" value=""><br />
Gender:<input type="radio" name="gender" value="male" />Male<input type="radio" name="gender" value="female" />Female<br />
Age:<select name="birthmonth" value="">
<option>Month</option>
<option>Janurary</option>
<option>Feburary</option>
<option>March</option>
</select>
<select name="birthday" value="">
<option>Day</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<input type="text" name="birthyear" size="4" maxlength="4" value="" /><br />
<br />
E-mail:<input type="text" name="email" size="15" maxlength="65" value=""><br />
Confirm E-mail:<input type="text" name="email2" size="15" maxlength="65" value=""><br />
<input type="submit" name="submit" size="15" maxlength="20" value="Register">
</form>
registernext.php file
Code:
<?php
include('confirm.php');
//test to see if username is alphanumeric
$test=$_POST[username];
if(!eregi(("[^A-Za-z0-9]"),$test)){
//test for duplicate names
$query="SELECT * FROM users WHERE user_name ='$_POST[username]'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num == 0){
//test for duplicate email
$query2="SELECT * FROM users WHERE user_email = '$_POST[email]'";
$result2=mysql_query($query2);
$num2=mysql_num_rows($result2);
if($num2==0){
//if emails and passwords match up
if(($_POST['pass']==$_POST['pass2'])&&($_POST['email']==$_POST['email2'])){
//generate random confirmation code
$confirm_code=md5(uniqid(rand()));
//get rid of all html from hackers
$name=strip_tags($_POST['username']);
$email=strip_tags($_POST['email']);
$pass=strip_tags($_POST['pass']);
$gender=strip_tags($_POST['gender']);
$birthday = strip_tags($_POST['birthday']) . strip_tags($_POST['birthmonth']) . strip_tags($_POST['birthyear']);
//insert data into database
$sql="INSERT INTO temp SET code='$confirm_code',user_name='$name',user_email='$email',user_password='$pass', user_gender='$gender',user_birthday='$birthday'";
$result=mysql_query($sql);
if($result){
$message="your confirm link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="[URL]http://likeftp.com/confirmation.php?passkey=$confirm_code[/URL]";
$sentmail=mail($email,'Registration Confirmation',"$message");
header("Location:thankyou.php");
}
else{
echo "Not found in our database ";
}
//if your email succesfully sent
if($sentmail){
echo "Your confirmation link has been sent to your email";
}
else{
echo "Cannot send confirmation link to your email address";
}
}else{
header("Location:usernametaken.html");
}
}else{
header("Location:invalidname.html");
}
}
}
?>
for some reason it keeps triggering my else statements instead of going to next step. The else statements it triggers is "error" and "Cannot send confirmation link to your email address" so im guessing the error is caused around if($result) but not sure. I need it to be successful and the the two tables i have in database are "temp" and "users"