Hello list,
I have the following problem with variables in my
program (well .. I'm new to PHP)
For exercising purposes I wrote a little guestbook-program,
which consists of a textarea for comments, a name-field and an e-mail addres, that must be filled in. After submitting the data, the latest contents of the textarea should be written in a file and echoed on top of the previously printed comments from the textarea.
But unfortunally, the contents of the form-variables are neither written to disk, nor displayed on screen.
I also found, that some variables could only be examined
when using the $_POST['var_name'] notation instead of just the $var_name.
Here is an extract of the code.
<html>
<head>
<title>Einfaches Gästebuch</title> //German ..
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="linen">
<h1>Einfaches Gästebuch</h1> //German ...
<form action="<?php echo $PHP_SELF; ?>" method="post">Your comment please:<br>
//<form action="guestbook.php" method="post">Your comment please:<br> <<<< THIS DOESN'T WORK...WHY ??
<textarea cols="55" rows="4" wrap="soft" name="comment"></textarea><br>
Ihr Name:<br>
<input Type="text" name="name"><br>
Ihre E-mail Address:<br>
<input type="text" name="email"> <input type="submit" value="Veröffentlichen"></form>
<h3>Previous Comments</h3>
<?php
// Store filename in Variable
$datei="comment.txt"; // the filename the data should be written to ..
// Variable comment set? Name und E-mail not empty?
// >>> $comment $name and $email DOES NOT WORK IN THE FOLLOWIN LINE -- WHY???
if (isset($_POST['comment']) && $_POST['name'] != "" && $_POST['email'] != "") {
// Test-printout follows, and it shows correct results ..
echo "All variables are correctly set\n";
echo $_POST['comment'] . "\n";
echo $_POST['name'] . "\n";
echo $_POST['email'] . "\n";
echo $datei; // the filename
// Open file
$zeiger=fopen($datei,"r+");
// Read data from file and store in in $alt
$alt=fread($zeiger,filesize($datei));
// E-mail-Link creation
$email="<a href=\"$email\">$email<a>";
// Get and format date ...
datum=date("j.n.Y");
// Remove slashes and \n ..
// "Assemble" the comment from the textarea ...
$meinung="<p><b>$name</b> ($email) wrote on <i>$datum</i>:<br>$comment</p>\n";
// Move filepointer to the beginning of the file ...
rewind($zeiger);
// Write new comment before the old one to file ...:
fputs($zeiger,"$meinung \n $alt");
// Close file
fclose($zeiger);
}
// Print entire File-contents (Comments)
readfile($datei);
?>
</body>
</html>
No comments of the textarea is written to the file, and not shown on the display.
Can someone explain me, why the $varname - notation (pointed out in this program) does not work, while the $_PUTS['varname'] does work?
ANy help is apreaciated.
Thanks in advance.
Regards ..
fred
I have the following problem with variables in my
program (well .. I'm new to PHP)
For exercising purposes I wrote a little guestbook-program,
which consists of a textarea for comments, a name-field and an e-mail addres, that must be filled in. After submitting the data, the latest contents of the textarea should be written in a file and echoed on top of the previously printed comments from the textarea.
But unfortunally, the contents of the form-variables are neither written to disk, nor displayed on screen.
I also found, that some variables could only be examined
when using the $_POST['var_name'] notation instead of just the $var_name.
Here is an extract of the code.
<html>
<head>
<title>Einfaches Gästebuch</title> //German ..
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="linen">
<h1>Einfaches Gästebuch</h1> //German ...
<form action="<?php echo $PHP_SELF; ?>" method="post">Your comment please:<br>
//<form action="guestbook.php" method="post">Your comment please:<br> <<<< THIS DOESN'T WORK...WHY ??
<textarea cols="55" rows="4" wrap="soft" name="comment"></textarea><br>
Ihr Name:<br>
<input Type="text" name="name"><br>
Ihre E-mail Address:<br>
<input type="text" name="email"> <input type="submit" value="Veröffentlichen"></form>
<h3>Previous Comments</h3>
<?php
// Store filename in Variable
$datei="comment.txt"; // the filename the data should be written to ..
// Variable comment set? Name und E-mail not empty?
// >>> $comment $name and $email DOES NOT WORK IN THE FOLLOWIN LINE -- WHY???
if (isset($_POST['comment']) && $_POST['name'] != "" && $_POST['email'] != "") {
// Test-printout follows, and it shows correct results ..
echo "All variables are correctly set\n";
echo $_POST['comment'] . "\n";
echo $_POST['name'] . "\n";
echo $_POST['email'] . "\n";
echo $datei; // the filename
// Open file
$zeiger=fopen($datei,"r+");
// Read data from file and store in in $alt
$alt=fread($zeiger,filesize($datei));
// E-mail-Link creation
$email="<a href=\"$email\">$email<a>";
// Get and format date ...
datum=date("j.n.Y");
// Remove slashes and \n ..
// "Assemble" the comment from the textarea ...
$meinung="<p><b>$name</b> ($email) wrote on <i>$datum</i>:<br>$comment</p>\n";
// Move filepointer to the beginning of the file ...
rewind($zeiger);
// Write new comment before the old one to file ...:
fputs($zeiger,"$meinung \n $alt");
// Close file
fclose($zeiger);
}
// Print entire File-contents (Comments)
readfile($datei);
?>
</body>
</html>
No comments of the textarea is written to the file, and not shown on the display.
Can someone explain me, why the $varname - notation (pointed out in this program) does not work, while the $_PUTS['varname'] does work?
ANy help is apreaciated.
Thanks in advance.
Regards ..
fred