Re: help with undefined variables, please

From: Date: Tue, 14 May 2002 17:30:41 +0000
Subject: Re: help with undefined variables, please
Groups: php.general 
Request: Send a blank email to php-general+get-97588@lists.php.net to get a copy of this message
hi- it is not REQUIRED for variables to be initialized in PHP, but if your error reporting is on too high, it will tell you, just to make sure you know. to turn your error reporting to a different level, you can change your php.ini: http://www.php.net/manual/en/configuration.php#ini.error-reporting or just change it for this script http://www.php.net/manual/en/function.error-reporting.php hope this helps, jerome
From: "The Gabster" <gabster_ro@yahoo.com> To: php-general@lists.php.net Subject: [PHP] help with undefined variables, please Date: Tue, 14 May 2002 12:21:45 -0500 Hello all! I have a newsletter script that works fine but I receive some undefined variables errors in Apache's error log: PHP Notice: Undefined variable: action in C:\Apache\htdocs\easyletter2\easyletter.php on line 73 PHP Notice: Undefined variable: action in C:\Apache\htdocs\easyletter2\easyletter.php on line 100 PHP Notice: Undefined variable: pw in C:\Apache\htdocs\easyletter2\easyletter.php on line 123 PHP Notice: Undefined variable: pw in C:\Apache\htdocs\easyletter2\easyletter.php on line 159 PHP Notice: Undefined variable: disp in C:\Apache\htdocs\easyletter2\easyletter.php on line 159 PHP Notice: Undefined variable: found in C:\Apache\htdocs\easyletter2\easyletter.php on line 75 PHP Notice: Undefined variable: pw in C:\Apache\htdocs\easyletter2\easyletter.php on line 123 PHP Notice: Undefined variable: pw in C:\Apache\htdocs\easyletter2\easyletter.php on line 159 Why do I get an undefined variable error for $action, $pw, $disp, $found when they do not have to be declared in the script? And the script is: <? # Version 1.1 Debugged, please upgrade older ones... ######################################################################## # Global Settings... ######################################################################## # Set the password for the eMail List editor! $pass="secret"; # Name of the datafile $filelocation="subscribers.txt"; # Title of the newsletter, will be displayed in the FROM field of the mailclient $lettername="Test"; # Your email, will be the reply-to mail $youremail="gabi@pattersongray.com"; ######################################################################## # Displayed Messages ######################################################################## # Welcome message displayed above the form for subscribing/unsubscribing $welcomemessage = "This is the place to subscribe and unsubscribe for the Onlinetools.org Newsletter. I will be sending this letter out every time there are some new tools or changes to the page. Your data will not be given to anyone and I send out small text mails only."; # Sorrymessage for failed subscription, will be followed by the email! $sorrysignmessage = "Sorry, there is already an entry for "; # Subscribe message, will be displayed when subscribing $subscribemessage = "Thank you for subscribing to the newsletter, a confirmation email is on its way!"; # Subscribemail, will be sent when someone subscribes. $subscribemail = "Thank you for subscribing to the newsletter."; # Unsubscribemessage for deletion, will be followed by the email! $unsubscribemessage = "We deleted the following entry: "; # Unsubscribemessage for failed deletion, will be followed by the email! $failedunsubscriptionmessage = "Sorry, you cannot unssubscribe as we didn't find an entry for "; ######################################################################## # Let the code begin... ######################################################################## # Checks if the file exists, if not creates a new one if (!file_exists($filelocation)) { $newfile = fopen($filelocation,"w+"); fclose($newfile); } # Open the datafile and read the content $newfile = fopen($filelocation,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); # Remove the slashes PHP automatically puts before special characters $content=stripslashes($content); # Reset the output of the "search result" $out=""; # Put the entries into the array lines $lines = explode("%",$content); for ($key=1;$key<sizeof($lines);$key++){ # when the email is not in the list, add the old entries if ($lines[$key] != $email){ $out .= "%".$lines[$key]; } # when it's already in the list, set found else { $found=1; } } ######################################################################## # Signing in ######################################################################## if ($action=="sign"){ # When there is already a subscription for this email *duh* if ($found==1){ # Display Sorrymessage echo "<div align=\"center\"><b>".$sorrysignmessage.$email."</b></div><br><br>"; $disp="yes"; } # otherwise, add the email to the list else { $disp="no"; $newfile = fopen($filelocation,"a+"); $add = "%".$email; fwrite($newfile, $add); fclose($newfile); # display the message of subscription echo "<div align=\"center\"><b>".$subscribemessage.$email."</b></div><br><br>"; # send confirmation Mail $submailheaders = "From: $lettername subscription form\n"; $submailheaders .= "Reply-To: $youremail\n"; mail ($email,$lettername." subscription",$subscribemail,$submailheaders); } } ######################################################################## # Signing out ######################################################################## if ($action=="delete"){ $disp="no"; # If the email is in the list... if ($found == 1){ $newfile = fopen($filelocation,"w+"); fwrite($newfile, $out); fclose($newfile); # display the message for deleted items... echo "<div align=\"center\"><b>".$unsubscribemessage.$email."</b></div><br><br>"; $disp="no"; } # if the email is not in the list if ($found != 1){ # display the message that tells that... echo "<div align=\"center\"><b>".$failedunsubscriptionmessage.$email."</b></div><br><br "; $disp="YES"; } } ######################################################################## # The core for the owner of the letter ######################################################################## if ($pw == $pass){ # When nothing was entered so far, display the form if ($send != "yes" && $send != "test"){ print'<form method="post"><input type="hidden" name=pw value='.$pass.'><input type="hidden" name=send value=yes> <br><b>Newsletter editor:</b><br><br> Subject:<br> <input type="text" name="subject" size=20><br> Message:<br> <textarea cols=50 rows=10 wrap="virtual" name="message"></textarea><br><br> <input type="submit" value="send"> </form>'; } # Predefine the Mail Settings for sending... $mailheaders = "From: $lettername\n"; $mailheaders .= "Reply-To:$youremail\n"; # add data in bcc fields # Data was ok, send button is pressed if ($send == "yes"){ $message=stripslashes($message); $subject=stripslashes($subject); $lines = explode("%",$content); for ($key=1;$key<sizeof($lines);$key++){ mail ($lines[$key],$subject,$message,$mailheaders); } print "<b>The following email has been sent!</b>"; print "<pre>$mailheaders\n$subject\n$message</pre>"; } } ######################################################################## # The Form for the users... ######################################################################## if ($pw != $pass && $disp != "no"){ print $welcomemessage; print' <div align="center"><form method="post"> <input type="text" name="email" value="foo@bar.com" size=30> <input type="radio" name="action" value="sign" checked>subscribe <input type="radio" name="action" value="delete">unsubscribe<br> <input type="submit" value="send"> </form></div> '; } print "<!-- Easyletter v1.1 Newsletterscript by Chris Heilmann, get yours @ http://www.onlinetools.org/easyletter/ -->"; ?> Thanks a lot, gabi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com

« previous php.general (#97588) next »