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

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";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.