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

Brian Kidd
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brian Kidd
UX Design Techdegree Graduate 36,466 Points

PHP File Handling: write_csv.php file not adding person to people.php

I have copied the code from the video exactly, yet I am not able to add another person to the people.csv file. I am not getting any errors and when I check the people.csv file as a .txt file, I do not see the person I added. Moreover, when I check the people.php file in the browser, I do not see any of the information of the person I added. I am not sure if this is a permissions issue, but I am working in WorkSpaces, so I do not see how this could be the case. Please advise and thank you very much. Below is my code: <?php

$new_person = [ filter_input(INPUT_POST, 'first', FILTER_SANITIZE_STRING), filter_input(INPUT_POST, 'last', FILTER_SANITIZE_STRING), filter_input(INPUT_POST, 'website', FILTER_SANITIZE_URL), filter_input(INPUT_POST, 'twitter', FILTER_SANITIZE_STRING), filter_input(INPUT_POST, 'img', FILTER_SANITIZE_URL) ];

if (($fh = fopen('../data/csv/people.csv', 'a+' ) ) !== false){ fseek($fh, -1, EEK_END); if (fgets($fh) != PHP_EOL){ fputs($fh, PHP_EOL); } fputcsv($fh, $new_person); fclose($fh); }

header('location:/people.php');

1 Answer

Brian Kidd
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brian Kidd
UX Design Techdegree Graduate 36,466 Points

ah, I figured it out. I just entered chmod 777 data/csv/people.csv to my console. Alena also let me know that she fixed this issue so that the people.csv file has the proper permissions.