Kahuki Webmaster Forum and Discussion Community  

Go Back   Kahuki Webmaster Forum and Discussion Community > Website Development & Management > Programming > PHP



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2006, 05:57 PM
Member
 
Join Date: Jan 2007
Posts: 80
dejan99 is on a distinguished road
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);
?>

Reply With Quote
  #2 (permalink)  
Old 11-24-2006, 06:10 PM
Member
 
Join Date: Oct 2006
Posts: 70
A!mee is on a distinguished road
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.

Reply With Quote
  #3 (permalink)  
Old 11-24-2006, 09:39 PM
Rookie
 
Join Date: Dec 2005
Posts: 5
Langer is on a distinguished road
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.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 09:55 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0