Jump to content

Archived

This topic is now archived and is closed to further replies.

Bobsterize

Creating a list

Recommended Posts

Hello guys,

First I must say, good job on the website, I really like it and it's happy to see fellow programmers/hackers willing to help others with php.
I learned html and javascript at the college and PHP is this coming semester, but honestly I can't wait. :)
Well, let me get right to it.
I am building a simple website that has 3-4 textboxes (Name, Address,...) and 1 button that will say Add or Submit.
Now each time a user goes to my website, fills in these information and clicks add, it will add his information to a list, and the list will keep growing with each user adding his info to the list.
The list can be on the same page or a different page and it is a public list that anyone who accesses the website can see the names of everyone and location.

EXAMPLE:
John Smith Ontario Canada
Angela Donavin California USA
.
.
.

Now I have a hosting plan with Mysql but writing the information to a textfile works too.

If I can get some help on how about doing that, I will pretty much appreciate it.

Thanks a lot and keep up the good work.

~Bob

Share this post


Link to post
Share on other sites
Do you intent to display this list as soon as anyone visits your site?
And do you plan to read all these names from the file each time someone visits your start page.
Or do you provide the list of names when someone clicks a button on your site?
I agree that, for the moment, you could do with a text file. Possibly an XML or just plain text?

If I can be of help, holler!

Ronald  8)

Share this post


Link to post
Share on other sites
Hey Ronald,
Yeah man, the list keeps updating everytime someone adds to it, and it will show right under the textboxes for everyone to see.

Example:
I go in the website.
I see 3-4 textboxes and a huge list of names under it
I fill in the textboxes, click add.
It will refresh the page (unless It doesnt need to refresh) and I will now see my name in the list along with everyone else.

The new user that added his name will apear on top of the list, so technically it's sorted by newed to older and possibly a date and time beside it when they added their names.

Thanks.

Share this post


Link to post
Share on other sites
Try this one for a start:

Before anyone shoots me:
1. There is no input cleansing
2. no check if file exists
3. no error checking

[code]<?php
$fn = "myfile.txt";

if (isset($_POST['_submit'])) {
  $text = array();
  // append you next entry to the file 
  $fh = fopen ($fn, 'a');
  fwrite ($fh, date("Y-m-d H:i:s ").$_POST['data']."\n");
  fclose ($fh);
}
  // read the file into an array, one line per array entry, sort reverse
  $text = file ($fn);
  rsort($text);
  echo '<div style="position:absolute;top: 70px;">';
  for ($i=0; $i<count($text); $i++)
    echo $text[$i] . '<br />';
  echo '</div>';
 
  echo '<form name="myform" method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  echo 'Add your name:<br />';
  echo '<input type="text" name="data" />';
  echo '<input type="hidden" name="_submit" value="1"/>';
  echo '<input type="submit" value="Add!" />';
  echo '</form>';
?>[/code]

Ronald   8)

Share this post


Link to post
Share on other sites

×

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.