PDA

View Full Version : PHP register form error


sydesign
03-20-2012, 06:19 PM
I am working on a membership registration form for a site and for some reason my code isn't working. looking through it i don't see anything that stands out as an error. but when I hit the submit button it just goes to a blank page. Is there something wrong with my code?

<?php

if($_POST['registerbtn'] ){
$getuser = $_POST['user'];
$getemail = $_POST['email'];
$getpass = $_POST['pass'];
$getretypepass = $_POST['retypepass'];

if($getuser){
if($getemail){
if($getpassword){
if($getretypepass){
if ($getpass === $getretypepass ){
if((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr(getemail, ".")) ){
require("./connect.php");

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){
$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){

$password = md5(md5("hJKHiug897".$password."hjklHhgKJHG8"));
$date = date("F d, Y");
$code = md5(rand());

mysql_query("INSERT INTO users VALUES ('', '$getuser', $password', '$getemail', '0', '$code', '$date')");

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows ($query);
if ($numrows == 1){

$site = "http://localhost/TBN";
$webmaster = "Mark Sy <mark@sydesigngraphics.com>";
$headers = "From: $webmaster";
$subject = "Activate your Account";
$message = "Thankyou for registering. Click the link below to activate your account.\n";
$message .= "$site/activate.php?user=$getuser&code=$code\n";
$message .= "You must activate your account to login.";

if (mail($getemail, $subject, $message, $headers) ){
$errormsg = "You have been registered. You must activate your account from the activation link to <b>$getemail</b>.";
$getuser = "";
$getemail = "";
}
else
$errormsg = "An error has occured. Your activation email was not sent.";
}
else
$errormsg = "An error has occured. Your account was not created.";
}
else
$errormsg = "There is already a user with that email.";
}
else
$errormsg = "There is already a user with that username.";

mysql_close();
}
else
$errormsg = "You must enter a valid email address to register.";
}
else
$errormsg = "Your passwords did not match.";
}
else
$errormsg = "You must retype your password to register.";
}
else
$errormsg = "You must enter your password to register.";
}
else
$errormsg = "You must enter your email to register.";
}
else
$errormsg = "You Must enter your username to register.";
}
else

$form = "<form action='./register.php' method='post'>
<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='user' value='$getuser'></td>
</tr> <tr>
<td>Email:</td>
<td><input type='text' name='email' value='$getemail'></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='pass' value=''></td>
</tr>
<tr>
<td>Retype:</td>
<td><input type='password' name='retypepass' value=''></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='registerbtn' value='register'></td>
</tr>
</table>
</form>";

echo $form;

?>

sydesign
03-20-2012, 09:17 PM
ok i fixed some of the original errors i noticed after posting this here is my current code. the error i get now is "An error has occurred. Your account was not created." which I'm assuming occurs at if ($numrows == 1){

I switched the form and the variables to the top which i noticed helps them work visually (when a submit error occurs yet the $getemail etc. stays in the form) however I'm not sure if it messes up any other part of the code. i just did it when i was playing around with it. the same error seems to occur when when i had the variable in the original spot too so i thought it to be no pertinent to the current issue. (whether or not it is causing another issue)

<?php

$getuser = $_POST['user'];
$getemail = $_POST['email'];
$getpass = $_POST['pass'];
$getretypepass = $_POST['retypepass'];


$form = "<form action='./register.php' method='post'>
<center><div style='background-image:url(images/memberegister.gif); background-repeat: no-repeat; width: 343px; height:120px; margin-top:50px;'></div><br />
<table style='background-color:#f0f0f0; padding:40px; border-style:solid; border-width:1px; border-color:#999;'>
<tr>
<td>Username:</td>
<td><input type='text' name='user' value='$getuser'></td>
</tr> <tr>
<td>Email:</td>
<td><input type='text' name='email' value='$getemail'></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='pass' value=''></td>
</tr>
<tr>
<td>Retype:</td>
<td><input type='password' name='retypepass' value=''></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='registerbtn' value='register'></td>
</tr>
</table>
<h6>&copy; The Buying Networks, LLC.</h6>
</center>
</form>";

if($_POST['registerbtn']){

if($getuser){
if($getemail){
if($getpass){
if($getretypepass){
if ($getpass === $getretypepass ){
if((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".")) ){
require("./connect.php");

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){
$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){

$password = md5(md5("hJKHiug897".$password."hjklHhgKJHG8"));
$date = date("F d, Y");
$code = md5(rand());

mysql_query("INSERT INTO users VALUES ('', '$getuser', $password', '$getemail', '0', '$code', '$date')");

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows ($query);
if ($numrows == 1){

$site = "http://localhost/TBN";
$webmaster = "Mark Sy <mark@sydesigngraphics.com>";
$headers = "From: $webmaster";
$subject = "Activate your Account";
$message = "Thank you for registering. Click the link below to activate your account.\n";
$message .= "$site/activate.php?user=$getuser&code=$code\n";
$message .= "You must activate your account to login.";

if (mail($getemail, $subject, $message, $headers) ){
echo "You have been registered. You must activate your account from the activation link to <b>$getemail</b>.";
$getuser = "";
$getemail = "";
}
else
echo "<center><font color='red'>An error has occurred. Your activation email was not sent. </center></font>$form";
}
else
echo "<center><font color='red'>An error has occurred. Your account was not created.</center></font>$form";
}
else
echo "<center><font color='red'>There is already a user with that email.</center></font>$form";
}
else
echo "<center><font color='red'>There is already a user with that username.</center></font>$form";

mysql_close();
}
else
echo "<center><font color='red'>You must enter a valid email address to register.</center></font>$form";
}
else
echo "<center><font color='red'>Your passwords did not match.</center></font>$form";
}
else
echo "<center><font color='red'>You must retype your password to register.</center></font>$form";
}
else
echo "<center><font color='red'>You must enter your password to register.</center></font>$form";
}
else
echo "<center><font color='red'>You must enter your email to register.</center></font>$form";
}
else
echo "<center><font color='red'>You must enter your username to register.</center></font>$form";
}
else

echo $form;

?>