Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gathering information online

Status
Not open for further replies.

Cosmiccradle

Technical User
Mar 24, 2003
63
NL
I'm busy setting up a site, one of the things I would like to see is a page where others can add names and places, so to be clear a person goes to my site and finds a page in which they can directly add a name and place from their own PC and that it can be seen right away on that page online. I've checked things like phpFormGenerator and PetiontionOnline but on both counts I'm not sure the information will show up on my site. Anyone have any ideas as to how to go about it, or if it's even possible?

Thanks in advance for any help.
 
of course it is possible. capturing form data is the basis of just about every interacting web application.

where will you be storing the user's input? in a database or in the server's file system?
 
Well, okay at least now I know it's possible, how do I go about it? I am using Cpanel and Supersite, and any programs avaliable via Fantastico.
 
i'm assuming you have no experience of php.
create a file on your webserver called form.php. put this code in it:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Type your name: <input type="text" name="uname" /><br/>
Type a place: <input type="text" name="uplace" /><br/>
<input type="submit" name="submit" value="Go" />
</form>
<hr/>
<?php
$filename = "data.txt";
if (isset($_POST['submit'])):
	$uname = empty($_POST['uname']) ? "Anonymous" : trim($_POST['uname']);
	$uplace = empty($_POST['uplace']) ? "No Place Provided" : trim($_POST['uplace']);
	if(!get_magic_quotes_gpc()):
		$uname = addslashes($uname);
		$uplace =addslashes($uplace);
	endif;
	$fh = fopen($filename, "a+bt") or die("Can't open storage file");
	fwrite ($fh, "\"$uname\",\"$uplace\"\r\n") or die("Cannot write to the storage file");
	fclose ($fh);
endif;
$i = 0;
$fh = @fopen($filename, "rb") or die("Nothing Uploaded Yet");
$content = "<table border=\"1\">\r\n<tr><td>Person</td><td>Place Name</td></tr>\r\n";
while (($data = fgetcsv($fh, 2024, ",")) !== FALSE):
	$content .= "<tr><td>{$data[0]}</td><td>{$data[1]}</td></tr>\r\n";
	$i++;
endwhile;
fclose($fh);
$content .= "</table>";
if ($i === 0):
	$content = "Nothing uploaded yet";
else:
	echo $content;
endif;
?>
</body>
</html>

hth
Justin
 
Do I place the folder in public_html or do I make a html page and place that in public_html like the rest? And I'm assuming I just chance the domain name to my own, correct?
 
what domain name?

and for the rest of your post - i don't understand i'm afraid! i don't know how your webserver is configured.

 
I'm not sure either as to what you understand under configuration, however I'm using Cpanel all my pages are published to the public_html folder after I've worked on them in Linkskysupersite. I gave your script a turn on the HTML editor in Cpanel and seemed to work fine except it didn't know where to publish the input when I tried it via my site. Now bare with me, I'm a newbie and know absolutely nothing about scripting hence the choice for a site builder. A bit of testing and I should figure it out, still have to make a folder as you suggested and find the proper placing, and see what that causes. Anyway, very kind of you to help because it's exactly what I'm looking for, glad that there are people like you willing to help with the expertise you posess.
 
sorry - i've never heard of linksysupersite and sfaik Cpanel is a utility for managing webs on linux boxes.

just put the code anywhere on your website. it doesn't matter where! if public_html works for you that's fine.

 
Then one last question in closing, the input screen is perfect, however underneath that a line and under that the following:

\r\nPersonPlace Name\r\n"; while (($data = fgetcsv($fh, 2024, ",")) !== FALSE): $content .= "{$data[0]}{$data[1]}\r\n"; $i++; endwhile; fclose($fh); $content .= ""; if ($i === 0): $content = "Nothing uploaded yet"; else: echo $content; endif; ?>

is there any way I can remove that without damaging the script?
 
Also it doesn't seem to be sending the information, nor is it showing up on the page after you click go, do I need to make contact with MySQL database?
 
the two issues are linked.

you have not perfectly cut and pasted the code i posted. or if you did, you have changed something to cause the table building part to break.

cut and paste the code again. take care not to change any of it.
 
I've done what you asked, to be sure I printed it out and rechecked everything if it was copied and pasted correctly, and removed any other codes present on the page so that only your code was present, however I got the same result. Sorry for being so trying.
 
Works great on your site, just proves it works and I'll have to get it working on mine. Thanks for the extra effort, if I was in the neighbourhood I'd buy you a beer or two.
 
;-)

just download the file and save it on your system.
make sure that you have got read-write permissions for that directory. CPanel should let you do this.
 
The text still creates the above problems, the php works fine but outside the site, not in the same page. But I'm still working on it to see if I can get it to work, the php form does work just need to find a way to embed it in my page, but the html editor won't allow me to embed the php form.
 
Doesn't look like it, but I ain't giving up, and won't bother you anymore, I'll just stare at the screen till it starts working.[dazed][thumbsup2]
 
if your editor won't let you code php then what are you using for php development?
 
I'll try and put it in steps, I use the linksky supersite's templates and site builder which is trellix based, when I'm done I go to Cpanel and use the HTML editor to fix things up for the visual effect like margins, buttons and the like save and it becomes a php page, that is to say that all the pages that I've made until now have the php extention. For the rest I'm not sure as to the ins and outs. But don't worry about it, I've taken up more then enough of your time, you've been kind enough to give me the script, now it's my cup of tea to get the thing up and running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top