bobahad Posted November 27, 2007 Share Posted November 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 27, 2007 Share Posted November 27, 2007 We can't use permanent storage. You have to. You have to store the information somewhere. An array is not something which keeps information throughout many requests. If it did, it would be permanent storage. You either have to store the mesages in a database or a text file. Quote Link to comment Share on other sites More sharing options...
bobahad Posted November 27, 2007 Author Share Posted November 27, 2007 We can only use a single session to do it. The form acts like a personal blog, a one time thing. 1) you fill in the information 2) you click post 3) stores them in an array 4) displays them under the form in a new table Quote Link to comment Share on other sites More sharing options...
xyn Posted November 27, 2007 Share Posted November 27, 2007 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() Quote Link to comment Share on other sites More sharing options...
bobahad Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
bobahad Posted November 28, 2007 Author Share Posted November 28, 2007 Awesome, I got my code to work without sessions or databases but can someone take a look at this code and let me know why the textarea is not printing. http://pastebin.com/df026b7a Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
bobahad Posted November 28, 2007 Author Share Posted November 28, 2007 Guys, I think the question was misunderstood, no other user is going to see the information, it's just a school project for introductory PHP, a simple array and loop program.... Anyways, there it is working, without sessions or database. http://www.welovepluto.com/MessageBoard2.php Thanks. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 I'd have to say what a pointless homework assignment Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.