Forum Moderators: coopster

Message Too Old, No Replies

Saving <INPUT TYPE="text"> data in array

         

redbanditos2005

2:49 pm on Jun 18, 2003 (gmt 0)

10+ Year Member



Hi there!
Following question:

I have on my site a form with 1 input field && 1 submit button and 1 "Next" button to stop and redirect the site, where I can write strings up to 50 chars down (special chars allowed!).
After sending the form I need to have the ability to write some next string and display all my input ordered list like.

How can I in a very simple way continuosly save the form data in a ordinary indexed array?

Thanx in advance for your answers...

greeetz

Redbanditos2005

DrDoc

5:03 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you looked into PHP sessions?

redbanditos2005

8:27 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



What do you mean sessions?
Could you give me a little bit more information...

brotherhood of LAN

11:21 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

You might want to start looking in the PHP Manual [uk.php.net] for info about sessions.

Basically a session is a way of uniquely identifying a certain user, usually through a 32byte session ID. It can be passed along through a cookie or URL through subsequent pages so you can keep track of this user (or any data associated with them).

The manual contains enough to get started on them .....

daisho

7:33 pm on Jun 20, 2003 (gmt 0)

10+ Year Member



Not sure what you are asking. If you want an array returned you can do something like:

<input type="text" name="var[]">
<input type="text" name="var[]">
<input type="text" name="var[]">
<input type="text" name="var[]">

In this example you will get an array named $_REQUEST['var'] in PHP that is an array of all the form items.

daisho.

redbanditos2005

6:55 am on Jun 23, 2003 (gmt 0)

10+ Year Member



Thx for your msg...

The thing is:

I need to save in mysql (Im working with phplib already) user inputs like textdocument titles.
So I want to do it with 1 textfield for the inputs, 1 "submit" button for sending it to $PHP_SELF, saving it continously in an array for later saving in mysql after clicking on 1 "next" button.
The array data should also be continously displayed above the form as a ordered list.

I dont have much experience in PHP-coding, so Im not sure if its possibile to do it in the way described above...

jatar_k

4:18 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well that shouldn't be too difficult.

When they hit the submit button you write to the db and then select the whole list from the db. Sort it and display it.

PHP MySQL Functions [ca.php.net]

sort() [ca.php.net] for sorting your array, there are also many other sort functions listed on this page.

redbanditos2005

6:40 am on Jun 24, 2003 (gmt 0)

10+ Year Member



Thx Jatar :-)!

In fact I was searching for some people who may have managed similar problem, but this cannot be done with only 1 textfield. Not only with HTML and PHP funcionality I think :-(( (except you're the best hacker on Earth ;-D)

So I made a "textfield list" with 1 "Add" and 1 "Delete" button for adding and deleting the content of the array and it works fine ;-)

vincevincevince

11:12 pm on Jun 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as said above, really check sessions - they are 10000% made for what you want. they allow variables to persist for a given user, between different pages, scripts, etc.... basically the same as storing data in a cookie, but stored on the server. (a cookie is normally automatically sent to the client to identify which session). your solution sounds fine though - even if it's not what you wanted.

pseudocode:
register session
read form data (if present), add to session variable
echo the form (form action to $PHPSELF)

that would do the job

redbanditos2005

8:04 am on Jun 26, 2003 (gmt 0)

10+ Year Member



Hi vincevincevince!

Do you can give me some code sample how a session registered array can be filled with input?

I use for my web frontend phplib, so I already have the session functionality - but Im still a newbie in PHP :-)

thx in advance...

Sander

12:13 am on Jul 2, 2003 (gmt 0)

10+ Year Member



When writing arrays to a database or to a $_GET variable, you may find this handy: [php.net ]