Log in

View Full Version : PHP form thing



Tabo
04-07-2007, 04:40 PM
I think you may need to point me to a free php download for this.

I need a shoutbox sort of thing (but not a shout box)

so a user fills out a form, with the fields:

field1
field2
field3
field4

Then it addds to the top of a page, above all the previous ones in the form of for example.

Field1 said field2 and then field3...

so it forms part like that ^

Also if possible i want it to be easy for me to add fields.

I made one but it is rubbish and allways writes over the previous form submition

mburt
04-07-2007, 05:07 PM
If it writes over the previous submission, you may want to add a file_get_contents() to the added data.
If you use a handle such as w+, or w, you need to do this. Example:

$data = file_get_contents("includes/mydata.txt").$form1.$form2.$etc;
We'll need to see the code to be more accurate though.

Tabo
04-07-2007, 05:21 PM
Yes it does overwrite and i do use that to get the messages, im bad at PHP and if you want to see it its really messy :S

mburt
04-07-2007, 05:31 PM
We do need to see it to help you, regardless of how bad it's written.
Here's an example though:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>write content</title>
</head>
<body>
<?php
$s = $_GET["send"];
$file = "path/to/myfile.txt";
$pfile = file_get_contents($file);
if (isset($s)) {
$handle = fopen($file,"w+");
$data = $pfile."\n<hr>"."<b>".$_POST["name"]."</b>"."<br>".$_POST["message"];
fwrite($handle,$data);
fclose($handle);
}
?>
<?php
echo $pfile;
?>
<hr>
<form method="post" action="?send">
Name:
<br><input type="text" name="name">
<br>Message:
<br><textarea name="message" rows="9" cols="46"></textarea>
<br><input type="submit">
</form>
</body>
</html>