uwannadonkey Posted September 13, 2007 Share Posted September 13, 2007 it was working before, but i added stuff, and now, its not working, so could someone help me figure out why it doesnt add to mysql/or show any errors? <?php include('inc/header2.php'); function print_errors($errors) { echo '<STRONG>'; foreach($errors as $error) { echo $error . '<BR>'; } echo '</STRONG><BR>'; } function sendConfirmationEmail($username, $password, $email, $activation_code, $note = '') { $activationURL = 'http://' . $_SERVER['HTTP_HOST'] . '/activate.php?user=' . urlencode($username) . '&code=' . $activation_code; $message = "Thank you for registering an account with our company. Go to the following URL to activate your account:\n\n$activationURL\n\nPlease keep the following information for your records.\n\nUsername: $username\nPassword: $password" . (($note) ? "\n\n$note" : ''); return mail($email, 'No-name account registration', str_replace("\n.", "\n..", $message), 'From: noreply@oursite.com'); } function resendConfirmationEmail($username) { if($result = @mysql_query('SELECT * FROM tradingsite WHERE username = "' . addslashes(preventTags($username)) . '"')) { if($user = @mysql_fetch_object($result)) { if($user->permission_level == NOT_ACTIVATED) { $tempPassword = ''; $length = intval(MAX_PASSWORD_LENGTH / 2); for($i = 0; $i < $length; ++$i) { $tempPassword .= chr(rand(48, 90)); } $tempMD5 = md5($tempPassword); if(@mysql_query('UPDATE tradingsite SET password = "' . $tempMD5 . '" WHERE id = ' . $user->id)) { return sendConfirmationEmail($username, $tempPassword, $user->email, $user->activation_code, 'NOTE: Because passwords cannot be recovered, a temporary password has been chosen for you. We recommend that you change it after you log in.'); } } } } return FALSE; } ?> <DIV class="contentheader">Account registration<HR></DIV> <?php $showRegistrationForm = TRUE; if(isset($_GET['resend'])) { if(resendConfirmationEmail($_GET['resend'])) { echo 'Confirmation e-mail sent.<BR>'; } else { echo 'Could not resend confirmation e-mail. Your account may have already been activated.<BR>'; } $showRegistrationForm = FALSE; } else if(isset($_POST['username']) && isset($_POST['displayname']) && isset($_POST['pass']) && isset($_POST['passconfirm']) && isset($_POST['email']) && isset($_POST['register']) && isset($_POST['email2'])&& isset($_POST['telephone'])&& isset($_POST['address'])&& isset($_POST['address2'])) { $errors = array(); $name2 = trim(preventTags($_POST['name'])); $var_address = trim(preventTags($_POST['address'])); $var_address2 = trim(preventTags($_POST['address2'])); $username = trim(preventTags($_POST['username'])); $telephone= trim(preventTags($_POST['number'])); $displayName = trim(preventTags($_POST['displayname'])); $password = $_POST['pass']; $cpassword = $_POST['passconfirm']; $email = trim(preventTags($_POST['email'])); $email2 = trim(preventTags($_POST['email2'])); $usernameLength = strlen(addslashes(preventTags($username))); $displayNameLength = strlen($displayName); $addressLength= strlen($var_address); $address2Length= strlen($var_address2); $telephoneLength = strlen($telephone); $passwordLength = strlen($password); $cpasswordLength = strlen($cpassword); $emailLength = strlen($email); $nameLength = strlen($name2); if($usernameLength == 0) { $errors[] = 'Username is blank.'; } else if($usernameLength < MIN_USERNAME_LENGTH) { $errors[] = 'Username too short (' . $usernameLength . ' characters). Your username must be between ' . MIN_USERNAME_LENGTH . ' and ' . MAX_USERNAME_LENGTH . ' characters.'; } else if($usernameLength > MAX_USERNAME_LENGTH) { $errors[] = 'Username too long (' . $usernameLength . ' characters). Your username must be between ' . MIN_USERNAME_LENGTH . ' and ' . MAX_USERNAME_LENGTH . ' characters.'; } if($displayNameLength == 0) { $errors[] = 'Display name is blank.'; } else if($displayNameLength < MIN_NAME_LENGTH) { $errors[] = 'Display name too short (' . $display_nameLength . ' characters). Your display name must be between ' . MIN_NAME_LENGTH . ' and ' . MAX_NAME_LENGTH . ' characters.'; } else if($displayNameLength > MAX_NAME_LENGTH) { $errors[] = 'Display name too long (' . $display_nameLength . ' characters). Your display name must be between ' . MIN_NAME_LENGTH . ' and ' . MAX_NAME_LENGTH . ' characters.'; } if($telephoneLength == 0) { $errors[] = 'Telephone number is blank.'; } else if($telephoneLength < 9) { $errors[] = 'Telephone number is too short (' . $passwordLength . ' characters). Your telephone must be at least 9 characters long.'; } if($nameLength == 0) { $errors[] = 'Name is blank.'; } else if($passwordLength < 3) { $errors[] = 'Password too short (' . $passwordLength . ' characters). Your Name must be at least 3 characters long.'; } if($passwordLength == 0) { $errors[] = 'Password is blank.'; } else if($passwordLength < MIN_PASSWORD_LENGTH) { $errors[] = 'Password too short (' . $passwordLength . ' characters). Your password must be at least ' . MIN_PASSWORD_LENGTH . ' characters long.'; } else if($cpasswordLength == 0) { $errors[] = 'Password confirmation field is blank.'; } else if($password != $cpassword) { $errors[] = 'Password fields did not match.'; } else if($addressLength == 0) { $errors[] = 'Address field not filled out.'; } else if($address2Length == 0) { $errors[] = 'Address field not filled out.'; } elseif($email != $email2) {$errors[] = 'Email Fields do not match.';} if($emailLength == 0) { $errors[] = 'E-mail address is blank.'; } $number = is_numeric($telephone); if($number == FALSE){ echo "Telephone number isnt a real number."; } else if(!preg_match('/^[A-Za-z0-9!#$%&\'*+\-\/=?^_`{|}~]+(\.[A-Za-z0-9!#$%&\'*+\-\/=?^_`{|}~]+)*@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)?\.([A-Za-z]{2,6}|[0-9]{1,3})$/', $email)) { $errors[] = 'Invalid e-mail address.'; } if(count($errors)) { print_errors($errors); } else { $result = @mysql_query('SELECT * FROM tradingsite WHERE username = "' . $username . '" OR email = "' . $email . '"'); if($result && @mysql_num_rows($result)) { while($user = @mysql_fetch_object($result)) { if($username == $user->username) { $errors[] = 'Username in use.'; } if($email == $user->email) { $errors[] = 'E-mail address in use.'; } if($name== $user->name) { $errors[] = 'Name is in use.'; } } print_errors($errors); } else { $dbUsername = addslashes($username); $dbDisplayName = addslashes($displayName); $dbName = addslashes($name2); $dbAddress = addslashes($var_address); $dbAddress2 = addslashes($var_address2); $dbPassword = md5($password); $dbEmail = addslashes($email); $activation_code = md5(microtime()); $query = 'INSERT INTO tradingsite (username, display_name, password, email, activation_code, perm, address1, address2, telephone,name) VALUES("' . $dbUsername . '", "' . $dbDisplayName . '", "' . $dbPassword . '", "' . $dbEmail . '", "' . $activation_code . '", 0, "' . $dbAddress . '", "' . $dbAddress2 . '", "' . $dbAddress2 . '", "' . $telephone. '", "' . $dbName. '" )'; if(@mysql_query($query)) { sendConfirmationEmail($username, $password, $email, $activation_code); echo '<STRONG>You have been registered. Please click login in top right corner to go back to main page! Ignore the Mail Error Above.</STRONG><BR><BR>'; $showRegistrationForm = FALSE; } else { echo '<STRONG>An error has occurred in the database. Your account could not be registered.</STRONG><BR><BR>'; } } } } if($showRegistrationForm) { ?> <BR> Beginning and ending spaces will be removed from the username.<BR><BR> <FORM method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration" id="registration"> <TABLE border="1"> <TR> <TD><STRONG><font color=#ffffff>Full Name:</STRONG></font></TD> <TD><INPUT type="text" name="name" id="name" size="32" maxlength="50" value="<?php if(isset($_POST['name'])) { echo $_POST['name']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff>Full Address:</font></STRONG></TD> <TD><INPUT type="text" name="address" id="address" size="32" maxlength="200" value="<?php if(isset($_POST['address'])) { echo $_POST['address']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff> </font></STRONG></TD> <TD><INPUT type="text" name="address2" id="address2" size="32" maxlength="200" value="<?php if(isset($_POST['address2'])) { echo $_POST['address2']; } ?>"><BR> </tr> <TR> <TR> <TD><STRONG><font color=#ffffff>Telephone</STRONG></font></TD> <TD><INPUT type="text" name="number" id="number" size="32" maxlength="50" value="<?php if(isset($_POST['name'])) { echo $_POST['name']; } ?>"><BR> </tr> <TD><STRONG><font color=#ffffff>E-mail address:</font></STRONG></TD> <TD><INPUT type="text" name="email" id="email" size="32" maxlength="200" value="<?php if(isset($_POST['email'])) { echo $_POST['email']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff>Confirm E-mail:</font></STRONG></TD> <TD><INPUT type="text" name="email2" id="email2" size="32" maxlength="200" value="<?php if(isset($_POST['email2'])) { echo $_POST['email2']; } ?>"><BR> </tr> <tr> </tr> <Tr></tr> <tr> <TD><STRONG><font color=#ffffff>Username:</STRONG></font></TD> <TD><INPUT type="text" name="username" id="username" size="32" maxlength="32" value="<?php if(isset($_POST['username'])) { echo $_POST['username']; } ?>"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Display name: </font></STRONG></TD> <TD><INPUT type="text" name="displayname" id="displayname" size="32" maxlength="32" value="<?php if(isset($_POST['displayname'])) { echo $_POST['displayname']; } ?>"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Password:</font></STRONG></TD> <TD><INPUT type="password" name="pass" id="pass" size="32" maxlength="32"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Confirm password:</font></STRONG></TD> <TD><INPUT type="password" name="passconfirm" id="passconfirm" size="32" maxlength="32"></TD> </TR> <DIV class="note"><font color=#ffffff>By registering, You accept the Laws and Terms of Service</DIV></TD></font> </TR> <tr> <td></td> </tr> </TABLE> <CENTER><INPUT type="submit" name="register" id="register" value="Register"></CENTER> </FORM> <?php } ?> <?php include('inc/footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
almightyegg Posted September 13, 2007 Share Posted September 13, 2007 $query = 'INSERT INTO tradingsite (`username`, `display_name`, `password`, `email`, `activation_code`, `perm`, `address1`, `address2`, `telephone`, `name`) VALUES("' . $dbUsername . '", "' . $dbDisplayName . '", "' . $dbPassword . '", "' . $dbEmail . '", "' . $activation_code . '", 0, "' . $dbAddress . '", "' . $dbAddress2 . '", "' . $dbAddress2 . '", "' . $telephone. '", "' . $dbName. '" )'; that should work. does everything else go ok...? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2007 Share Posted September 13, 2007 Remove all the @ error supressor symbol. Quote Link to comment Share on other sites More sharing options...
uwannadonkey Posted September 13, 2007 Author Share Posted September 13, 2007 thx for replying: by errors, i meant errors that are specified in my code: password field not filled out, ETC its not regisitering me, and its not giving any errors, why? <?php include('inc/header2.php'); function print_errors($errors) { echo '<STRONG>'; foreach($errors as $error) { echo $error . '<BR>'; } echo '</STRONG><BR>'; } function sendConfirmationEmail($username, $password, $email, $activation_code, $note = '') { $activationURL = 'http://' . $_SERVER['HTTP_HOST'] . '/activate.php?user=' . urlencode($username) . '&code=' . $activation_code; $message = "Thank you for registering an account with our company. Go to the following URL to activate your account:\n\n$activationURL\n\nPlease keep the following information for your records.\n\nUsername: $username\nPassword: $password" . (($note) ? "\n\n$note" : ''); return mail($email, 'No-name account registration', str_replace("\n.", "\n..", $message), 'From: noreply@oursite.com'); } function resendConfirmationEmail($username) { if($result = mysql_query('SELECT * FROM tradingsite WHERE username = "' . addslashes(preventTags($username)) . '"')) { if($user = mysql_fetch_object($result)) { if($user->permission_level == NOT_ACTIVATED) { $tempPassword = ''; $length = intval(MAX_PASSWORD_LENGTH / 2); for($i = 0; $i < $length; ++$i) { $tempPassword .= chr(rand(48, 90)); } $tempMD5 = md5($tempPassword); if(mysql_query('UPDATE tradingsite SET password = "' . $tempMD5 . '" WHERE id = ' . $user->id)) { return sendConfirmationEmail($username, $tempPassword, $user->email, $user->activation_code, 'NOTE: Because passwords cannot be recovered, a temporary password has been chosen for you. We recommend that you change it after you log in.'); } } } } return FALSE; } ?> <DIV class="contentheader">Account registration<HR></DIV> <?php $showRegistrationForm = TRUE; if(isset($_GET['resend'])) { if(resendConfirmationEmail($_GET['resend'])) { echo 'Confirmation e-mail sent.<BR>'; } else { echo 'Could not resend confirmation e-mail. Your account may have already been activated.<BR>'; } $showRegistrationForm = FALSE; } else if(isset($_POST['username']) && isset($_POST['displayname']) && isset($_POST['pass']) && isset($_POST['passconfirm']) && isset($_POST['email']) && isset($_POST['register']) && isset($_POST['email2'])&& isset($_POST['telephone'])&& isset($_POST['address'])&& isset($_POST['address2'])) { $errors = array(); $name2 = trim(preventTags($_POST['name'])); $var_address = trim(preventTags($_POST['address'])); $var_address2 = trim(preventTags($_POST['address2'])); $username = trim(preventTags($_POST['username'])); $telephone= trim(preventTags($_POST['number'])); $displayName = trim(preventTags($_POST['displayname'])); $password = $_POST['pass']; $cpassword = $_POST['passconfirm']; $email = trim(preventTags($_POST['email'])); $email2 = trim(preventTags($_POST['email2'])); $usernameLength = strlen(addslashes(preventTags($username))); $displayNameLength = strlen($displayName); $addressLength= strlen($var_address); $address2Length= strlen($var_address2); $telephoneLength = strlen($telephone); $passwordLength = strlen($password); $cpasswordLength = strlen($cpassword); $emailLength = strlen($email); $nameLength = strlen($name2); if($usernameLength == 0) { $errors[] = 'Username is blank.'; } else if($usernameLength < MIN_USERNAME_LENGTH) { $errors[] = 'Username too short (' . $usernameLength . ' characters). Your username must be between ' . MIN_USERNAME_LENGTH . ' and ' . MAX_USERNAME_LENGTH . ' characters.'; } else if($usernameLength > MAX_USERNAME_LENGTH) { $errors[] = 'Username too long (' . $usernameLength . ' characters). Your username must be between ' . MIN_USERNAME_LENGTH . ' and ' . MAX_USERNAME_LENGTH . ' characters.'; } if($displayNameLength == 0) { $errors[] = 'Display name is blank.'; } else if($displayNameLength < MIN_NAME_LENGTH) { $errors[] = 'Display name too short (' . $display_nameLength . ' characters). Your display name must be between ' . MIN_NAME_LENGTH . ' and ' . MAX_NAME_LENGTH . ' characters.'; } else if($displayNameLength > MAX_NAME_LENGTH) { $errors[] = 'Display name too long (' . $display_nameLength . ' characters). Your display name must be between ' . MIN_NAME_LENGTH . ' and ' . MAX_NAME_LENGTH . ' characters.'; } if($telephoneLength == 0) { $errors[] = 'Telephone number is blank.'; } else if($telephoneLength < 9) { $errors[] = 'Telephone number is too short (' . $passwordLength . ' characters). Your telephone must be at least 9 characters long.'; } if($nameLength == 0) { $errors[] = 'Name is blank.'; } else if($passwordLength < 3) { $errors[] = 'Password too short (' . $passwordLength . ' characters). Your Name must be at least 3 characters long.'; } if($passwordLength == 0) { $errors[] = 'Password is blank.'; } else if($passwordLength < MIN_PASSWORD_LENGTH) { $errors[] = 'Password too short (' . $passwordLength . ' characters). Your password must be at least ' . MIN_PASSWORD_LENGTH . ' characters long.'; } else if($cpasswordLength == 0) { $errors[] = 'Password confirmation field is blank.'; } else if($password != $cpassword) { $errors[] = 'Password fields did not match.'; } else if($addressLength == 0) { $errors[] = 'Address field not filled out.'; } else if($address2Length == 0) { $errors[] = 'Address field not filled out.'; } elseif($email != $email2) {$errors[] = 'Email Fields do not match.';} if($emailLength == 0) { $errors[] = 'E-mail address is blank.'; } $number = is_numeric($telephone); if($number == FALSE){ echo "Telephone number isnt a real number."; } else if(!preg_match('/^[A-Za-z0-9!#$%&\'*+\-\/=?^_`{|}~]+(\.[A-Za-z0-9!#$%&\'*+\-\/=?^_`{|}~]+)*@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)?\.([A-Za-z]{2,6}|[0-9]{1,3})$/', $email)) { $errors[] = 'Invalid e-mail address.'; } if(count($errors)) { print_errors($errors); } else { $result = mysql_query('SELECT * FROM tradingsite WHERE username = "' . $username . '" OR email = "' . $email . '"'); if($result && mysql_num_rows($result)) { while($user = mysql_fetch_object($result)) { if($username == $user->username) { $errors[] = 'Username in use.'; } if($email == $user->email) { $errors[] = 'E-mail address in use.'; } if($name== $user->name) { $errors[] = 'Name is in use.'; } } print_errors($errors); } else { $dbUsername = addslashes($username); $dbDisplayName = addslashes($displayName); $dbName = addslashes($name2); $dbAddress = addslashes($var_address); $dbAddress2 = addslashes($var_address2); $dbPassword = md5($password); $dbEmail = addslashes($email); $activation_code = md5(microtime()); $query = 'INSERT INTO tradingsite (`username`, `display_name`, `password`, `email`, `activation_code`, `perm`, `address1`, `address2`, `telephone`, `name`) VALUES("' . $dbUsername . '", "' . $dbDisplayName . '", "' . $dbPassword . '", "' . $dbEmail . '", "' . $activation_code . '", 0, "' . $dbAddress . '", "' . $dbAddress2 . '", "' . $dbAddress2 . '", "' . $telephone. '", "' . $dbName. '" )'; if(mysql_query($query)) { sendConfirmationEmail($username, $password, $email, $activation_code); echo '<STRONG>You have been registered. Please click login in top right corner to go back to main page! Ignore the Mail Error Above.</STRONG><BR><BR>'; $showRegistrationForm = FALSE; } else { echo '<STRONG>An error has occurred in the database. Your account could not be registered.</STRONG><BR><BR>'; } } } } if($showRegistrationForm) { ?> <BR> Beginning and ending spaces will be removed from the username.<BR><BR> <FORM method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration" id="registration"> <TABLE border="1"> <TR> <TD><STRONG><font color=#ffffff>Full Name:</STRONG></font></TD> <TD><INPUT type="text" name="name" id="name" size="32" maxlength="50" value="<?php if(isset($_POST['name'])) { echo $_POST['name']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff>Full Address:</font></STRONG></TD> <TD><INPUT type="text" name="address" id="address" size="32" maxlength="200" value="<?php if(isset($_POST['address'])) { echo $_POST['address']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff> </font></STRONG></TD> <TD><INPUT type="text" name="address2" id="address2" size="32" maxlength="200" value="<?php if(isset($_POST['address2'])) { echo $_POST['address2']; } ?>"><BR> </tr> <TR> <TR> <TD><STRONG><font color=#ffffff>Telephone</STRONG></font></TD> <TD><INPUT type="text" name="number" id="number" size="32" maxlength="50" value="<?php if(isset($_POST['name'])) { echo $_POST['name']; } ?>"><BR> </tr> <TD><STRONG><font color=#ffffff>E-mail address:</font></STRONG></TD> <TD><INPUT type="text" name="email" id="email" size="32" maxlength="200" value="<?php if(isset($_POST['email'])) { echo $_POST['email']; } ?>"><BR> </tr> <TR> <TD><STRONG><font color=#ffffff>Confirm E-mail:</font></STRONG></TD> <TD><INPUT type="text" name="email2" id="email2" size="32" maxlength="200" value="<?php if(isset($_POST['email2'])) { echo $_POST['email2']; } ?>"><BR> </tr> <tr> </tr> <Tr></tr> <tr> <TD><STRONG><font color=#ffffff>Username:</STRONG></font></TD> <TD><INPUT type="text" name="username" id="username" size="32" maxlength="32" value="<?php if(isset($_POST['username'])) { echo $_POST['username']; } ?>"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Display name: </font></STRONG></TD> <TD><INPUT type="text" name="displayname" id="displayname" size="32" maxlength="32" value="<?php if(isset($_POST['displayname'])) { echo $_POST['displayname']; } ?>"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Password:</font></STRONG></TD> <TD><INPUT type="password" name="pass" id="pass" size="32" maxlength="32"><BR> </TR> <TR> <TD><STRONG><font color=#ffffff>Confirm password:</font></STRONG></TD> <TD><INPUT type="password" name="passconfirm" id="passconfirm" size="32" maxlength="32"></TD> </TR> <DIV class="note"><font color=#ffffff>By registering, You accept the Laws and Terms of Service</DIV></TD></font> </TR> <tr> <td></td> </tr> </TABLE> <CENTER><INPUT type="submit" name="register" id="register" value="Register"></CENTER> </FORM> <?php } ?> <?php include('inc/footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.