SolveErrors
PHP

PHP-General - Header tag not directing to specified page

111 views

I had my redirects working, then I added a few statements at the front to make an error array, and now the redirect to the login page after all the requirements (ie. submit and pass and username, and the username not being taken) are met, the header doesn't actually force the page to login.php, but the die statement shows. Where am I going wrong?
PHP Code:
    error_reporting(E_ALL); 
     require 
'#evan/includes/common.php';
    
    if(isset(
$_POST['submitted'])) {
        
$error = array();
        
        if(empty(
$_POST['username'])) {
            
$error[]="Please enter a username!";
        }
        if(empty(
$_POST['password'])) {
            
$error[]="Please enter a password!";
        }            
    }
    if(isset(
$_POST['submitted'])) 
    { 
        if(empty(
$error)){
            
$query = " 
                SELECT 
                    id 
                FROM users 
                WHERE 
                    username = :username 
            "
; 
            
$query_params = array( 
                
':username' => $_POST['username'] 
            ); 
             
            try 
            {  
                
$stmt = $db->prepare($query); 
                
$result = $stmt->execute($query_params); 
            } 
            catch(
PDOException $ex) 
            {  
                die(
"Failed to run query: " . $ex->getMessage()); 
            } 
            
$row = $stmt->fetch();
             
            if(
$row) 
            { 
                
$error_user = "Username already taken!";
            
            } else {
                
$query = " 
                    INSERT INTO users ( 
                        username, 
                        password, 
                        salt 
                    ) VALUES ( 
                        :username, 
                        :password, 
                        :salt 
                    ) 
                "
; 
                      
                
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); 
                
$password = hash('sha256', $_POST['password'] . $salt); 
                
$query_params = array( 
                    
':username' => $_POST['username'], 
                    
':password' => $password, 
                    
':salt' => $salt 
                
); 
                 
                try 
                { 
                    
$stmt = $db->prepare($query); 
                    
$result = $stmt->execute($query_params); 
                } 
                catch(
PDOException $ex) 
                { 
                    die(
"Failed to run querywetewrt"); 
                } 
               
                
header("Location: http://XX.XX.XX.XXX/evan/login.php"); 
                die(
"Redirecting to #"); 
            }
            
        } else{
            
$error_message = '';
            foreach(
$error as $key => $values) {
                
$error_message.= "$values";
            }
            
$error_message.=""
;
        }
    }
     

?> 







echo "$error_message";
    if (isset(
$_GET['E'])) {
        echo 
$_GET['E'];
    }
    echo 
$error_user;
?>

 
    
      
        
          Username*

        
        
          
        

      
      
        
          Password*
        
        
          
        

      
      
        
          
            
              Create Account!
            
          

        

      
      
        Should be Empty:
        
      
    
  

  
  

More PHP fixes

index.php wont load index.html will loadHow to cut down the size of a URL?Warning: oci_free_statement(): 3 is not a valid oci8 statement resourcePage 2 - str_replacePHP-General - Variabses wont loadSyntax help - $random_name