Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Writing CSV

The Add Person is not adding Ryan Carson.

the write_csv.php code is as follows:


$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, SEEK_END); if (fgets($fh) != PHP_EOL) { fputs($fh, PHP_EOL); } fputcsv($fh,$new_person); fclose($fh); } header('location: /people.php');

The Add_Person.php code is as follows:

<?php /**

  • Form for adding more people to the csv file
  • first,last,website,twitter,img */ $title = 'Add Person'; require 'inc/header.php'; ?> <form method="post" action="inc/write_csv.php"> <div class="form-group input-group-lg"> <label class="control-label" for="first">First Name</label> <input class="form-control" type="text" name="first" id="first" /> </div>

    <div class="form-group input-group-lg"> <label for="last">Last Name</label> <input class="form-control" type="text" name="last" id="last" /> </div>

    <div class="form-group input-group-lg"> <label for="website">Website</label> <div class="input-group input-group-lg"> <span class="input-group-addon" id="website-addon">http://</span> <input class="form-control" aria-describedby="website-addon" type="text" name="website" id="website" /> </div> </div>

    <div class="form-group input-group-lg"> <label for="twitter">Twitter</label> <div class="input-group input-group-lg"> <span class="input-group-addon" id="twitter-addon">@</span> <input class="form-control" aria-describedby="twitter-addon" type="text" name="twitter" id="twitter" /> </div> </div>

    <div class="form-group input-group-lg"> <label for="img">Image</label> <input class="form-control" type="text" name="img" id="img" placeholder="http://" /> </div>

    <button class="btn-lg btn-default" type="submit"><?php echo $title; ?></button> </form> <?php require 'inc/footer.php';