0

Hi I cant understand why I get the following error:

"Notice: Undefined index: note in C:\wamp\www\addressbook\guesbook.php on line 20"

The code I have is below:

<html><head><title>My Guestbook</title></head>
<body>
<h1>Welcome to my Guestbook</h1>
<h2>Please write me a little note below</h2>
<?php 
    $me = $_SERVER['PHP_SELF'];
?>
<form action="<?php echo $me; ?>" method="POST">
<textarea cols=40 rows=5 name=note wrap=virtual></textarea>
<br>
<input type=submit value=" Send it ">
</form>
<?php 
//error_reporting(0);
$msg = stripslashes($_POST['note']);
if(isset($msg)) {
$fp = fopen("notes.txt","a") or die("Can't open file");

fputs($fp, $msg);
fclose($fp);
}
?>

<h2>The entries so far:</h2>
<?php @ReadFile("notes.txt") ?>
</body></html>

The line it is complaining about is:

$msg = stripslashes($_POST['note']);

Please can someone help me nderstand why I am getting this. I have switched off error_reporting to get around this temorarily.

Many thanks
Shuel

1
Contributor
1
Reply
5
Views
6 Years
Discussion Span
Last Post by Shuel
1

Hi I cant understand why I get the following error:

"Notice: Undefined index: note in C:\wamp\www\addressbook\guesbook.php on line 20"

The code I have is below:

<html><head><title>My Guestbook</title></head>
<body>
<h1>Welcome to my Guestbook</h1>
<h2>Please write me a little note below</h2>
<?php 
    $me = $_SERVER['PHP_SELF'];
?>
<form action="<?php echo $me; ?>" method="POST">
<textarea cols=40 rows=5 name=note wrap=virtual></textarea>
<br>
<input type=submit value=" Send it ">
</form>
<?php 
//error_reporting(0);
$msg = stripslashes($_POST['note']);
if(isset($msg)) {
$fp = fopen("notes.txt","a") or die("Can't open file");

fputs($fp, $msg);
fclose($fp);
}
?>

<h2>The entries so far:</h2>
<?php @ReadFile("notes.txt") ?>
</body></html>

The line it is complaining about is:

$msg = stripslashes($_POST['note']);

Please can someone help me nderstand why I am getting this. I have switched off error_reporting to get around this temorarily.

Many thanks
Shuel

Sorted now. for the benefit of others, it was due to the variable not being correctly set.

have managed to get round this by setting dummy value:

if (!isset($_POST['note'])){
   $_POST['note'] = "undefined";
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.