Jump to content

Recommended Posts

Not sure why but it says I have an unexpected $end to my document. I know that means unbalanced curly braces but I don't see where the issue is.

 

<?php

// Include the database page
require ('../inc/dbconfig.php');
require ('../inc/global_functions.php');

//Login submitted
if (isset($_POST['submit'])) { 
    
    // Errors defined as not being any
    $errors = false;
    
    // Assign variable values if there is values
    if (trim($_POST['username']) == '') { $errors = true; }
    if (trim($_POST['password']) == '') { $errors = true; }
    if (trim($_POST['password2']) == '') { $errors = true; }
    if (trim($_POST['email']) == '') { $errors = true; }
    if (trim($_POST['firstName']) == '') { $errors = true; }
    if (trim($_POST['lastName']) == '') { $errors = true; }
    if ((!is_numeric($_POST['question1'])) || ($_POST['question1'] == 0)) {$errors = true;}
    if ((!is_numeric($_POST['question2'])) || ($_POST['question2'] == 0)) {$errors = true;}
    if (trim($_POST['answer1']) == '') { $errors = true; }
    if (trim($_POST['answer2']) == '') { $errors = true; }
    
    // Error checking, make sure all form fields have input
if ($errors) {

        // Not all fields were entered error
        $message = "You must enter values to all of the form fields!";
        
        $output = array('errorsExist' => $errors, 'message' => $message);
        
} else {
    
        // Send email address to function for validating
        $checkEmail = validEmail(mysqli_real_escape_string($dbc,$_POST['email']));
        
        // Find out if email address is valid
        if ($checkEmail == false) {
            
            // Email is not valid error
            $errors = true;
            $message = "You must enter a valid email address!";
            
            $output = array('errorsExist' => $errors, 'message' => $message);
            
        } else if ($_POST['question1'] == $_POST['question2']) { // Both questions must not be the same
            
            // Both questions are the same error
            $errors = true;
            $message = "You must select two different questions!";
            
            $output = array('errorsExist' => $errors, 'message' => $message);  
            
        } else if ($_POST['answer1'] == $_POST['answer2']) { // Both answers must not be the same
            
            // Both answers are the same error
            $errors = true;
            $message = "You must enter two different answers!";
            
            $output = array('errorsExist' => $errors, 'message' => $message);  
            
        } else {
      
            // No errors reported 
            // Escape post data
            $username = mysqli_real_escape_string($dbc,$_POST['username']);
            $password = mysqli_real_escape_string($dbc,$_POST['password']);
            $password2 = mysqli_real_escape_string($dbc,$_POST['password2']);
            $email = mysqli_real_escape_string($dbc,$_POST['email']);
            $firstName = mysqli_real_escape_string($dbc,$_POST['firstName']);
            $lastName = mysqli_real_escape_string($dbc,$_POST['lastName']);
            $question1 = mysqli_real_escape_string($dbc,$_POST['question1']);
            $question2 = mysqli_real_escape_string($dbc,$_POST['question2']);
            $answer1 = mysqli_real_escape_string($dbc,$_POST['answer1']);
            $answer2 = mysqli_real_escape_string($dbc,$_POST['answer2']);
            
            // Query the database for user info with username
            $query = "SELECT * FROM manager_users WHERE username = '".$username."' OR emailAddress = '".$email."'";
            $result = mysqli_query($dbc,$query);
            
            // Count number of returned results from query
            if (mysqli_num_rows($result) == 0) {
                
                // Fetch returned data from result set
                $row = mysqli_fetch_array($result);
                
                // Find out if the password is the same as the confirm password
                if ($password == $password2) {
                    
                    // Assign hashed password to variable
                    $passForDB = GenPassHash($password);
                    
                    // No user found ready to insert new user with query
                    $query = "INSERT INTO manager_users (username, password, password2, emailAddress, firstName, lastName) VALUES ('".$username."','" . $passForDB[0] . "','" . $passForDB[1] . "','".$email."','".$firstName."','".$lastName."')";
                    $result = mysqli_query($dbc,$query);
                    
                    // Get insert ID
                    $id = mysqli_insert_id($dbc); 
                    
                    // Find the highest existing userID
                    $query2 = "SELECT MAX(userID) FROM manager_users";
                    $result2 = mysqli_query($dbc,$query2);
                    $row2 = mysqli_fetch_row($result2);
                    
                    // Get highest UserID
                    $userID = $row2[0];
                    
                    // Develop activation key for new user
                    $registrationKey =  substr(md5(mt_rand()), 0, 5);
                    
                    // Increase userId by 1 to get new userID
                    $userID = $userID + 1;
                    
                    // Update new user with new userID
                    $query = "UPDATE manager_users SET userID = '".$userID."' WHERE id = '".$id."'";
                    $result = mysqli_query($dbc,$query);
                        
                    // Insert new registration into separate table
                    $query2 = "INSERT INTO manager_users_registrations (userID, registrationDate, registrationKey, verifyHash, ipAddress) VALUES ('".$userID."',CURRENT_TIMESTAMP,'".$registrationKey."','".$verifyHash."','".$ipAddress."')";
                    $result2 = mysqli_query($dbc,$query2);
                    
                    // Insert secret questions and answers for user
                    $query3 = "INSERT INTO manager_users_secretAnswers (userID, questionID, answer) VALUES ('".$userID."','".$question1."','".$answer1."')";
                    $result3 = mysqli_query($dbc,$query3);
                    
                    $query4 = "INSERT INTO manager_users_secretAnswers (userID, questionID, answer) VALUES ('".$userID."','".$question2."','".$answer2."')";
                    $result4 = mysqli_query($dbc,$query4);
                    
                    $query5 = "SELECT * FROM manager_users WHERE userID = '".$userID."'";
                    $result5 = mysqli_query($dbc,$query5);
                    $row5 = mysqli_fetch_row($result5);
                    
                    $myMD5string = $userID.$email.$registrationKey;
                    $verifyHash = md5($myMD5string);
                    
                    $query6 = "UPDATE manager_users_registrations SET verifyHash = '".$verifyHash."' WHERE userID = '".$userID."'";
                    $result6 = mysqli_query($dbc,$query6);
                    
                    // Email user new registration account
                    $sender_email = "noreply@kansasoutlawwrestling.com";
                    $reply_to = "noreply@kansasoutlawwrestling.com";
                    $recipient_email = $email; 
                    $email_subject = "KOW Manager Account Registration";
            
                    $email_body = 'Hello '.$firstName.' '.$lastName.' Welcome to our website!<br /><br />You, or someone using your email address, has completed registration at '.my_domain_name().'. You can complete registration by clicking the following link:<br /><br /><a href="http://www.'.my_domain_name().'/manager/verify.php?userID='.$userID.'&verifyHash='.$verifyHash.'">http://www.'.my_domain_name().'/manager/verify.php?userID='.$userID.'&verifyHash='.$verifyHash.'</a><br /><br />If this is an error, ignore this email and you will be removed from our mailing list.<br /><br />Regards, '.my_domain_name().' Team';
                    
                    mailSomeone($email, $sender_email, $email_subject, $email_body);
                    
                    $query7 = "INSERT INTO manager_users_logins (userID, numberOfLogins, lastOnline) VALUES ('".$userID."','0','0000-00-00 00:00:00')";
                    $result7 = mysqli_query($dbc,$query7);
                    $query8 = "INSERT INTO manager_users_hacking (userID, lockDate) VALUES ('".$userID."','0000-00-00 00:00:00')";
                    $result8 = mysqli_query($dbc,$query8);
                    
                    // Registration was sucessful
                    $errors = false;
                    $message = "Registration was successful please check the account you gave for a verification email!";
            
                    $output = array('errorsExist' => $errors, 'message' => $message); 
                    
                } else {
                    
                    // Passwords did not match
                    $errors = true;
                    $message = "You must enter the same password for the confirm password!";
            
                    $output = array('errorsExist' => $errors, 'message' => $message); 
                    
                }            
    
            } else {
               
               // User doesn't exist in database error
               $message = "Sorry there is already an account set up with that username or email address, please check your username and email address and try again!";
               
               $output = array('errorsExist' => $errors, 'message' => $message); 
                
            }
           
        }
    
    }
            
}

//Output the result
$output = json_encode($output);
echo $output;

?>

Link to comment
https://forums.phpfreaks.com/topic/244277-unexpected-end/
Share on other sites

The posted code does not produce an unexpected $end error.

 

Are you sure the error was being reported in that file or one of the required files?

 

back to what PFM asked, are you sure that this error is triggered in your main php file and not in a required one, paste the error(s) that you are receving

Link to comment
https://forums.phpfreaks.com/topic/244277-unexpected-end/#findComment-1254826
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.