• I know this is a fairly common problem and it is usually ascribed to white space. I have a template with a redirect and I am getting this error:

    Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\WP\wp-includes\general-template.php:2406) in C:\xampp\htdocs\WP\wp-content\themes\2014-child\form-template.php on line 46

    I really can’t see white space and cannot see what is wrong. line 2406 in the general-template.php file is thus:

    echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
    		includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";

    Line 46 in the form-template reads thus:

    header("Location:localhost/wp/success-page/");?>

    But I’m including the entire form-template in case the error is actually generated from something prior to line 46:

    <?php
    /**
     * The template for displaying pages
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages and that
     * other "pages" on your WordPress site will use a different template.
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     *  Template Name: form-template.php
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    			<?php // Include the page content template.
    			get_template_part( 'content', 'page' ); ?>
    
    <?php
    $film_title = $_POST["title"];
    $film_year = $_POST["year"];
    $film_link = $_POST["link"];
    $film_genre = $POST["genre"];
    $film_decade = $POST["decade"];
    $film_smpic = $POST["sm-pic"];
    
    $servername = "localhost";
    $username = "root";
    $password = "********";
    
    $conn =  mysqli_connect($servername, $username, $password);
    
    if (!$conn) {
    	die("Connection failed: ".mysqli_error());
    }
    
    // Data insertion into database
    $query = "INSERT INTO 'movies'.'films' ( 'alpha-name', 'year', 'page-link', 'genre', 'decade','sm-pic' ) VALUES ( $film_title, $film_year, $film_link, $film_genre,$film_decade,$film_smpic)";
    mysqli_query($conn, $query);
    
    // Redirection to the success page
    header("Location:localhost/wp/success-page/");?>
    
    	</main><!-- .site-main -->
    	</div><!-- .content-area -->

    I understand that there are probably other errors in this code that prevent it from being functional, but right now I’m just trying to solve this header error.

Viewing 1 replies (of 1 total)
  • Dion

    (@diondesigns)

    The problem is that you cannot use header() once you have started outputting HTML. The following part of your code MUST be executed before you call the get_header() function:

    <?php
    $film_title = $_POST["title"];
    $film_year = $_POST["year"];
    $film_link = $_POST["link"];
    $film_genre = $POST["genre"];
    $film_decade = $POST["decade"];
    $film_smpic = $POST["sm-pic"];
    
    $servername = "localhost";
    $username = "root";
    $password = "********";
    
    $conn =  mysqli_connect($servername, $username, $password);
    
    if (!$conn) {
    	die("Connection failed: ".mysqli_error());
    }
    
    // Data insertion into database
    $query = "INSERT INTO 'movies'.'films' ( 'alpha-name', 'year', 'page-link', 'genre', 'decade','sm-pic' ) VALUES ( $film_title, $film_year, $film_link, $film_genre,$film_decade,$film_smpic)";
    mysqli_query($conn, $query);
    
    // Redirection to the success page
    header("Location:localhost/wp/success-page/");?>

    I will also add that your code will not work since you are not specifying a database in your call to mysqli_connect().

Viewing 1 replies (of 1 total)
  • The topic ‘redirect not working’ is closed to new replies.