Jump to content

50 messages Array


bobahad

Recommended Posts

Hello guys,

I have asked this yesterday in the phpfreaks channel on mIRC but still haven't got a real answer.

I have to create a form that a single user fills in and clicks Post. When Post is clicked, it will add all the information entered in 4 arrays then creates a table at the bottom of the page. Now I got the table to create, but the problem is, everytime I click "Post", it keeps overwriting the same array key therefore overwriting the same table.

 

The form that I created is at http://www.welovepluto.com/MessageBoard.php

 

my code is at: http://pastebin.com/m472f0b54

 

So once again initials goes into an array

subject goes into another array

message goes into another array

date/time goes into an array

 

So when "Post" is clicked all those arrays will store the values in the correspondant Key

then create a new table under the form everytime with the new values.

 

We can't use permanent storage.

 

Can someone please take a look at my code and help.

Link to comment
Share on other sites

Use sessions.

 

$_SESSION['MyArray'] = array(1,2,3,4,5,6,7,;

 

or

 

$tmp[] = $_POST['name'];
$tmp[] = $_POST['subject'];
$tmp[] = $_POST['message'];
$_SESSION['MyArray'] = $tmp;

print_r($_SESSION['MyArray']);

 

NOTE/EDIT: this will only be stored for the user the session is set with, and only visible to this user.

Once sessions expire, your array is Bye bye.

 

Use: use http://php.net/fwrite()

Link to comment
Share on other sites

xyn, I love you, this works awesome but one final problem, yes it's suppose to be only for 1user and for 1 session.

How do I make it print a new table everytime, post is clicked using a loop.

 

Please take a look at my code, it seems the loops never ends.

 

Form: http://www.welovepluto.com/MessageBoard.php

Code: http://pastebin.com/d5f724a35

 

Thanks :)

Link to comment
Share on other sites

You need some storage method, you can't get the data to be viewed by another user as its carried by sessions, the whole point of sessions is a monoserver interaction not a polyserver interaction that you can get off a database.  You need to write the arrays in a text file of some sort or db them, peroid.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.