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

Writing CSV

The Add Person is not adding Ryan Carson.

the write_csv.php code is as follows:

<?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, 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';