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

PHP writing blank variable to file

If I try to just write $post_data to the text file it works just fine. But when I try to use $htmlMix I end up with <span></span>. No data from $_POST makes it through. Any ideas?

<?php
    $post_data = $_POST['sendie'];
    $htmlMix = '<span>' . $post_data . '</span>' ;
        $filename ='data.txt';
        $fp = fopen($filename, "a+");      
        fwrite($fp, $htmlMix . "\n");
         fclose($fp);
?>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

It looks like the variables are fine to me... unless I've come late to the post and it's already been changed :)

It looks like a problem with the PHP POST variable. Could you check in your HTML/PHP that the name attribute is set for the correct form field? Otherwise all that will get written if anything is the span elements. :)

Thanks

Throughout your whole script you're not using a valid variable name for the fp variable.

$gross;

^ a valid variable is structured like that.

Please mark my answer as the 'best answer' if it helps you out!

Ah, chalk that up to a typo when I posted it to the forum. I should've just pasted it. -.- See anything else that may be the issue?