OBJECTIVE: When a visitor goes to index.php and clicks the enter button, it will add the input from "field1" into the $dAta array. AND, this is the most important, it will save the entries into the $dAta array.

CURRENT: This is the code that i have for now. When i type something into "field1" and click enter, i see the new entry into the array with the print_r. But when i exit and go back to open the index.php the added entry is not there.

THEORY: Any ideas??? Does this require the use of f.open, f.write. f.close? Im thinking something along the lines of scanning the existing array into a temporary array, add then entry from field 1, then write the new array to a new php file? Thanks.

---------CODE SECTION BELOW----------
<?php
$dAta = array(1 => "961204","961205","961206",);
?>

<FORM METHOD="POST" ACTION="index.php">
<input name="field1" type="text" size="80" value="">
<INPUT TYPE=submit VALUE="Enter">

<?php
$dAta[] = $_POST[field1];
print_r($dAta);
?>

    1. Each time you load a webpage, the PHP script is executed again. As such, each page view is separate and unique. If you want PHP to use data from the previous page, then yes, you will have to write the data to a file. My suggestion would be to use [man]serialize/man the array and write that string to the file. Then, when you read the file back in ([man]file_get_contents/man would be all that's needed here), you'd simply use the [man]unserialize/man function to get the array back.

    2. In regards to this line of code:

      $dAta[] = $_POST[field1]; 

      Array indeces in your case should be strings. $row[name] does not have a string as an index, but a constant. PHP will detect this (assuming there actually isn't a constant named 'name') and throw an E_WARNING and then assume it is a string. So, use quotes: $row['name'].

      Write a Reply...