Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Aug 2013
    Location
    DeKalb, IL
    Posts
    2
    Member #
    37008

    HTML form to PHP array not working

    This is my first post here. I've got this chunk of code to send info from an html form to a php array to do some simple manipulations. But, PHP is not recognizing this as an array. I'm sure this code worked previously. Now I'm just stuck at this point. Any help would be lovely.

    Here's my html code:

    <form method="post" action="directors.php">
    <h1>Film Directors</h1>
    Enter name of favorite Directors:

    <p><input type="text" name="directors[]"></p>
    <p><input type="text" name="directors[]"></p>
    <p><input type="text" name="directors[]"></p>
    <p><input type="text" name="directors[]"></p>

    <p><input type="submit" value="submit"></p>
    </form>

    And the PHP code:

    echo "<b>Form Entry Order</b> <ul>";
    for ($i=0; $i<count($directors); $i++)
    {
    echo "<li> $directors[$i] </li>";
    }

    echo "</ul> <p><b>Alphabetical Order</b> <ul>";
    sort($directors);
    foreach ($directors as $d)
    {
    echo "<li> $d </li>";
    }

    echo "</ul> <p><b>Reverse Order</b> <ul>";
    rsort($directors);
    $i=0;
    while ($i<count($directors))
    {
    echo "<li> $directors[$i] </li>";
    $i++;
    }
    echo "</ul>";

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    PHP Code:
    <?php

    // POST the array from HTML into a PHP array.
    $directors=$_POST['directors'];

    // That's it ... now $directors is an array.
    // PHP automatically knows it is an array because of the way you defined "directors[]"

    // Sort it
    sort($directors);

    // Let's test it out ...
    foreach($directors as $director){
    echo 
    "Director: ".$director."<br />";
    }

    ?>


  4. #3
    Junior Member
    Join Date
    Aug 2013
    Location
    DeKalb, IL
    Posts
    2
    Member #
    37008
    Awesome, perfect, and thanks.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 12:32 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com