php 4.3.1 scripts are showing error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

php 4.3.1 scripts are showing error

Post by harsha »

this script is showing an error

Notice: Undefined index: a in D:\usr\pub\nazo\index.php on line 2
Notice: Undefined index: submit in D:\usr\pub\nazo\index.php on line 3

when i see the output

the script is here

can anyone here tell me why this error is there



<?php
$a = $HTTP_GET_VARS['a'];
$submit=$HTTP_POST_VARS['submit'];
switch ($a)
{
case 'view':

echo "this is the view page";

break;

case 'validate':
if($submit){

$errmsg="";

//below section checks that name feild is empty or not/////////////////////////////////////

if(empty($name))
{
echo "<font color=\"red\" size=\"1\" face=\"verdana\">You failed to enter your name</font><br>";
}

//below section checks that email feild is empty or not/////////////////////////////////////////////

if(empty($email))
{
echo "<font color=\"red\" size=\"1\" face=\"verdana\">You failed to enter your email address</font>";
}
///////////////////////////below section checks that you have enter place or not

if(empty($place))
{
echo "<font color=\"red\" size=\"1\" face=\"verdana\">You failed to enter your place</font>";
}
///////////////////////////below section checks that you have enter message or not

if(empty($message))
{
echo "<br><font color=\"red\" size=\"1\" face=\"verdana\">You failed to enter your message</font>";
}

//if every thing is filled////////////////////////////////

if(!empty($name)&&!empty($email)&& !empty($place)&&!empty($message))
{

/////////////////////////////checks for the correct format of the email////////////////////////////////

if(!eregi("^[A-za-z0-9\_-]+@[A-za-z0-9\_-]+.[A-za-z0-9\_-]+.*",$email))
{
$errmsg.="Your email address is not in a correct format";
echo <<< THIS
<font color="red" face="verdana" size="+1">Your email address is not in a correct format</font>
THIS;
}



//////////////////////////////end of email check///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
include 'smile.php';
$HTTP_POST_VARS['message']=$message;
////////////////////////////if error message is empty///////////////////////////////

if(empty($errmsg))
{
$filename="data.txt";
$fptr=fopen($filename,"r");
$content=fread($fptr,filesize ($filename));
fclose($fptr);

////////////////////////////checks whether email already exits or not//////////////////////////////////

if(strstr($content,$email))
{
echo "<br><font color=\"red\" size=\"1\" face=\"verdana\">You have already signed the guest book</font>";
}
else
{
echo "<center><font face=\"verdana\" color=\"red\" size=\"1\">Thank you for signing our Guest book!!<br>";
echo "The following data has been added to the guest book</font>";
echo "<p align=\"center\">".(htmlspecialchars($name))."<br>".$email."<br>".(nl2br($message))."<br>".$place."</p>";
echo "<a href=\"view.php\">view our Guestbook</a></center>";
/////////////////////////////
$fp = fopen('data.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("d.F.Y") . "#" . $HTTP_POST_VARS['name'];
$line .= "#" . $HTTP_POST_VARS['email'];
$line .= "#" . ucfirst($HTTP_POST_VARS['message']);
$line .= "#" . ucfirst($HTTP_POST_VARS['place']);
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
}//end of else

}
//error message is empty do a above
///////////////////////////
}
}

break;

default:
echo <<< END
<html>
<head>
<link rel="stylesheet" href="sign.css" type="text/css">
</head>
</body bgcolor="gainsboro" text="#000000">

<table width=80% align=right cellpadding=0 cellspacing=0 border=0 valign=top height=250>
<tr> <td width=50%>

<form action="index.php?a=validate" method="POST" name="guest">
<br><b>name:</b><br><input type="text" name="name">*
<br><b>E-mail:</b><br><input type="text" name="email">*
<br><b>Place:</b><br><input type="text" name="place">*
<br><b>Message:</b>*<br>
</b><textarea cols="40" rows="10" name=message></textarea><br><br>
<input type="submit" value="sign!" class="button">
<input type="reset" name="reset" class="button">
</form>
</td>
<td height=50% align=center valign=top>
<br><br>
<b>Smileys:</b><br><br>
<script language="JavaScript" src="script.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
function setSmile(str)
{
obj = document.guest.message;
obj.focus();
obj.value = obj.value + str;
}
//-->
</script>
<a href="javascript:setSmile(' :) ')"><img src="img/smile.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' ;) ')"><img src="img/wink.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' 8) ')"><img src="img/cool.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :J ')"><img src="img/curve-smile.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :P ')"><img src="img/tongue.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :D ')"><img src="img/biggrin.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :( ')"><img src="img/frown.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :o ')"><img src="img/astonish.gif" width="15" height="15" border="0"/></a>
<br>
<a href="javascript:setSmile(' %) ')"><img src="img/crazy.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :[] ')"><img src="img/fright.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :smoke: ')"><img src="img/smoke.gif" width="21" height="20" border="0"/></a>
<a href="javascript:setSmile(' :evil: ')"><img src="img/evil.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :apple: ')"><img src="img/apple.gif" width="15" height="15" border="0"/></a>
<a href="javascript:setSmile(' :moo: ')"><img src="img/moo.gif" width="16" height="16" border="0"/></a>

<br><br><a href="index.php?a=view">[View Guestbook]</a>
</td></tr></table>
</body>
</html>
END;

break;

}//end switch
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

First off, the error message (well notice actually) tells you that the errors are on lines 2 and 3 - in that case you only really needed to post the first 5 lines of the code instead of the whole script. Plus it makes it much nicer if you put php code inbetween these tags [syntax=php]and[/syntax] because then it's all nicely highlighted and easier to read.

Now for the error - it is there because $HTTP_GET_VARS['a'] and $HTTP_POST_VARS['submit'] are not set. Could you show us the code for the form this comes from?

Mac
Post Reply