Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Basic PHP Website (2018) Adding a Basic Form Redirecting After a Form Submission

Vladislav Mavrin
PLUS
Vladislav Mavrin
Courses Plus Student 3,125 Points

thanks.php is a blank page

Hi

after submitting the form I am redirected, but thanks.php turns out to be a blank page. I checked its code and it seems OK to me. Would appreciate your help, thanks thanks.php

<?php
$pageTitle = "Thank you";
$section = null;
include ("inc/header.php");

?>


<div class="section page">
    <h1>Your suggestion</h1>
    <p>Thanks for the email! I&rsquo;ll check out your suggestion!</p>
</div>

<?php
include ("inc/footer.php");
?>
Clare A
Clare A
23,994 Points

Hi,

I don't have answer you're looking for but thought it worth mentioning that I just replaced the contents of my local thanks.php file with your code and the redirect page displayed correctly - so it may not be an issue with the snippet above. Were you able to see the correct url, header and/or footer and was the redirect call in process.php ok?

Vladislav Mavrin
Vladislav Mavrin
Courses Plus Student 3,125 Points

Hi Clare, suggest.php looks just fine, the I submit the form and get redirected to the blank thanks.php

here are my codes for process.php and suggest.php suggest.php

<?php 
$pageTitle = "Suggest a media item";
$section = "suggest";
include ("inc/header.php"); ?>
<div class="section page">
    <div class="wrapper">
<h1>Suggest a media item</h1>
<p>If you think smth is missing</p>
<form method="post" action="process.php">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input type="text" id="name "name="name" />
            </td>
        </tr>
        <tr>
            <th>
                <label for="email">Email</label>
            </th>
            <td>
                <input type="text" id="email "name="email" />
            </td>
        </tr>
        <tr>
            <th>
                <label for="details">Suggest Item Details</label>
            </th>
            <td>
                <textarea id="details "name="details"></textarea>
            </td>
        </tr>
    </table>
    <input type="submit" value="Send">

</form>
</div>
</div>
<?php include ("inc/footer.php"); ?>

process.php

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$details = $_POST["details"];
echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .=  "Email " . $email . "\n";
$email_body .=  "Details " . $details . "\n";
echo $email_body;
echo "</pre>";
//To do: Send email
header ("location:thanks.php");
?>

Also, If I move thanks.php code to process.php, process.php is displayed correctly alt text

1 Answer

Vladislav Mavrin
PLUS
Vladislav Mavrin
Courses Plus Student 3,125 Points

Suddenly thanks.php started to work. Have not changed anything. Probably there was some stuff going on on my server.