Welcome Guest, Not a member yet? Register   Sign In
Redirect issues
#1

(This post was last modified: 05-09-2019, 08:55 PM by ciadmin.)

Hello again!

Im tryting to redirect one page to another but having a hard time. I added the controller/function in HEADER field and hit submit but keep getting a 404 error and in url space this is what appears: http://culturedkink.com/index.html. Im trying to figure out why index.html show up? Here is the php code for the page:

Code:
<?php
// Include config file
require_once "application/config/database.php";
 
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
 
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
 
    // Validate username
    if(empty($_POST["username"])){
        $username_err = "Please enter a username.";
    } else{
        // Prepare a select statement
        $sql = "SELECT id FROM users WHERE username = ?";
        
        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "s", $param_username);
            
            // Set parameters
            $param_username = trim($_POST["username"]);
            
            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
                /* store result */
                mysqli_stmt_store_result($stmt);
                
                if(mysqli_stmt_num_rows($stmt) == 1){
                    $username_err = "This username is already taken.";
                } else{
                    $username = trim($_POST["username"]);
                }
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
         
        // Close statement
        mysqli_stmt_close($stmt);
    }
    
    // Validate password
    if(empty($_POST["password"])){
        $password_err = "Please enter a password.";     
    } elseif(strlen(trim($_POST["password"])) < 6){
        $password_err = "Password must have atleast 6 characters.";
    } else{
        $password = trim($_POST["password"]);
    }
    
    // Validate confirm password
    if(empty($_POST["confirm_password"])){
        $confirm_password_err = "Please confirm password.";     
    } else{
        $confirm_password = trim($_POST["confirm_password"]);
        if(empty($password_err) && ($password != $confirm_password)){
            $confirm_password_err = "Password did not match.";
        }
    }
    
    // Check input errors before inserting in database
    if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
        
        // Prepare an insert statement
        $sql = "INSERT INTO users (username, password) VALUES (?, ?)";
         
        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
            
            // Set parameters
            $param_username = $username;
            $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
            
            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
                // Redirect to login page
                
               header("location:".base_url()."index.php/register/log");
            } else{
                echo "Something went wrong. Please try again later.";
            }
        }
         
        // Close statement
        mysqli_stmt_close($stmt);
    }
    
    // Close connection
    mysqli_close($link);
}
?>

** EDITED TO USE BBCODE SO IT DOESN'T RUN ON**

Im trying to figure why html comes up and not php. Do I create another controller or make changes to another file. BTW register/log is controller and function.

Heart Heart ,
Mekaboo
Reply


Messages In This Thread
Redirect issues - by Mekaboo - 05-09-2019, 07:31 PM
RE: Redirect issues - by php_rocs - 05-10-2019, 06:39 AM
RE: Redirect issues - by Mekaboo - 05-10-2019, 06:50 PM
RE: Redirect issues - by Wouter60 - 05-10-2019, 10:30 AM
RE: Redirect issues - by Mekaboo - 05-10-2019, 06:51 PM
RE: Redirect issues - by InsiteFX - 05-11-2019, 08:26 AM
RE: Redirect issues - by Mekaboo - 05-12-2019, 08:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB