Bobsterize Posted August 30, 2006 Share Posted August 30, 2006 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 CanadaAngela 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 Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 30, 2006 Share Posted August 30, 2006 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) Quote Link to comment Share on other sites More sharing options...
Bobsterize Posted August 30, 2006 Author Share Posted August 30, 2006 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 itI 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. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 30, 2006 Share Posted August 30, 2006 Try this one for a start:Before anyone shoots me:1. There is no input cleansing2. no check if file exists3. 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) Quote Link to comment Share on other sites More sharing options...
Bobsterize Posted August 30, 2006 Author Share Posted August 30, 2006 I will give it a try and let you know.Thanks a lot. 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.