![]() |
| |||
| PHP - saving results from new array entry - PHP ? 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); ?> |
| |||
| You actually would want to use a database for something like this, or if it is just a per user basis, a cookie. PHP doesn't have built in memory without using one of these options. You could use the file functions, but those functions lock the text file so noone else can read/write to that text file until the lock is released. This isn't an issue for small apps that only one person is likely to use at a time, but for web apps that multiple users can be on concurrently, it becomes an issue. Even if the lock is only for a moment, as more users are on the site the likelihood of it being locked when someone else is trying to use it will increase. |
| |||
| You need to add your array to a session variable or some other permanent storage system, because PHP is without state. Additionally, you aren't really cuing the array to expand on post. <? session_start(); if(!isset($_SESSION['dAta'])) { $_SESSION['dAta'] = array("961204","961205","961206"); } if(isset($_POST['submit'])) { $arr = $_SESSION['data']; $arr[] = $_POST['field1']; $_SESSION['dAta'] = $arr; print_r($_SESSION['dAta']; } ?> <form method="post"> <input id="field1" name="field1" type="text" size="80" value="<? echo $_POST['field1']; ?>" /> <input type="submit" id="submit" name="submit" value="ENTER" /> </form> Anyplace you want to use the session variable, make sure you have session_start() at the top of that page. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get immediate Pay per click results? | Eric_Storm | Pay-Per-Click Marketing | 4 | 10-21-2008 09:27 AM |
| extract a numerical value entry from a text field?? | UNO | JavaScript | 2 | 05-01-2007 04:23 AM |
| How to Update MYSQL database table based on mysql query array? | blackfox | PHP | 2 | 03-30-2007 02:11 AM |
| Array | GeminiAce | JavaScript | 1 | 11-26-2006 09:01 PM |
| Dreamweaver 8.0 Saving Problems...can you help? | valar2007 | Webdesign & HMTL | 3 | 09-23-2006 12:59 PM |