I got a problem with this code, which should take take a username and a comment from two forms in a html doc, and place the text in a file.
<form action="FormHandler.php" method="POST">
<INPUT type="text" NAME="username" size="30"> <BR>
<TEXTAREA NAME="comment" ROWS=6 COLS=60></TEXTAREA><br>
<input type="submit" value="Send form">
<INPUT TYPE=reset VALUE="Clear">
</form>
<?php
function write() {
$filename = "wall.txt";
$info = $username && "<br>" && $comment;
$line = "<br>----------------------------------------------------<br>";
$openfile = fopen("$filename", "a");
$writetext = $line && $info;
fwrite($openfile, $writetext);
fclose($openfile);
}
write();
?>
But $username is undefined, it says. Can anybody help me out here? If you see another error somewhere, please notice me about that too.
Thanks.
Undefined variable.
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try
Mac
Code: Select all
<form action="FormHandler.php" method="post">
<input type="text" name="username" size="30" /><br />
<textarea name="comment" rows="6" cols="60"></textarea><br />
<input type="submit" value="Send form" />
<input type=reset value="Clear" />
</form>
<?php
function write() {
$filename = 'wall.txt';
$info = $_POSTї'username']."\n".$_POSTї'comment']."\n";
$line = "\n----------------------------------------------------\n";
$openfile = fopen($filename, 'a');
$writetext = $line.$info;
fwrite($openfile, $writetext);
fclose($openfile);
}
write();
?>Shouldn't there be a line like this:
Otherwise it will just write blank things when they just view the form.
Code: Select all
<?PHP
if(isset($_POSTї'username']) && isset($_POSTї'comment']))
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK