Results 1 to 8 of 8

Thread: Notice: Undefined variable:

  1. #1
    Join Date
    Mar 2015
    Location
    Dronfield, Derbyshire
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Notice: Undefined variable:

    Hi,

    I have an issue with a simple PHP email form on my website, which worked prior to us moving website host, but is now only partially sending information through via email.

    It was recommended that I turned on error messaging to diagnose the problem(s) which I did.

    The error which is repeated is: -

    Notice: Undefined variable: first_lot_number in /var/www/vhosts/sheffieldauctiongallery.com/httpdocs/verify.php on line 207

    Here is my code: -

    Code:
    <?php
    					if(isset($_POST['email'])) {
    						 
    						// EDIT THE 2 LINES BELOW AS REQUIRED
    						$email_to = "emailaddressremoved";
    						$email_subject = "subjectremoved";
    						
    						ini_set('display_errors',1); 
    						error_reporting(E_ALL);
    						 
    						 
    						function died($error) {
    							// your error code can go here
    							echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    							echo "These errors appear below.<br /><br />";
    							echo $error."<br /><br />";
    							echo "Please go back and fix these errors.<br /><br />";
    							die();
    						}
    						 
    						// validation expected data exists
    						if(!isset($_POST['auctiondate']) ||
    							!isset($_POST['forename']) ||
    							!isset($_POST['surname']) ||
    							!isset($_POST['email']) ||
    							!isset($_POST['telephone']) ||
    							!isset($_POST['address']) ||
    							!isset($_POST['agreement'])) {
    							died('We are sorry, but there appears to be a problem with the form you submitted.');
    						}
    						 
    						$auctiondate = $_POST['auctiondate']; // required
    						$forename = $_POST['forename']; // required
    						$surname = $_POST['surname']; // required
    						$email_from = $_POST['email']; // required
    						$telephone = $_POST['telephone']; // not required
    						$address = $_POST['address']; // required
    						$agreement = $_POST['agreement']; // required
    						 
    						$error_message = "";
    						$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
    					  if(!eregi($email_exp,$email_from)) {
    						$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    					  }
    						$string_exp = "^[a-z .'-]+$";
    					  if(!eregi($string_exp,$forename)) {
    						$error_message .= 'The forename you entered does not appear to be valid.<br />';
    					  }
    					    $string_exp = "^[a-z .'-]+$";
    					  if(!eregi($string_exp,$surname)) {
    						$error_message .= 'The surname you entered does not appear to be valid.<br />';
    					  }
    					  if(strlen($address) < 2) {
    						$error_message .= 'The Address you entered do not appear to be valid.<br />';
    					  }
    					  if(strlen($error_message) > 0) {
    						died($error_message);
    					  }
    						$email_message = "Form details below.\n\n";
    						 
    						function clean_string($string)
    						{
    							$bad = array("content-type","bcc:","to:","cc:","href");
    							return str_replace($bad,"",$string);
    						}
    						
    						$email_message .= "Date of Auction: ".clean_string($auctiondate)."\n";
    						
    						$email_message .= "Conditions of Sale: ".clean_string($agreement)."\n";
    						 
    						$email_message .= "First Lot Number: ".clean_string($first_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($first_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($first_lot_bid)."\n\n";
    						
    						$email_message .= "Second Lot Number: ".clean_string($second_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($second_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($second_lot_bid)."\n\n";
    						
    						$email_message .= "Third Lot Number: ".clean_string($third_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($third_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($third_lot_bid)."\n\n";;
    						
    						$email_message .= "Forth Lot Number: ".clean_string($forth_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($forth_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($forth_lot_bid)."\n\n";
    						
    						$email_message .= "Fifth Lot Number: ".clean_string($fifth_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($fifth_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($fifth_lot_bid)."\n\n";
    						
    						$email_message .= "Sixth Lot Number: ".clean_string($sixth_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($sixth_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($sixth_lot_bid)."\n\n";
    						
    						$email_message .= "Seventh Lot Number: ".clean_string($seventh_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($seventh_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($seventh_lot_bid)."\n\n";
    						
    						$email_message .= "Eighth Lot Number: ".clean_string($eighth_lot_number)."\n";
    						$email_message .= "Description: ".clean_string($eighth_lot_description)."\n";
    						$email_message .= "Max Bid in GBP, excl premium: ".clean_string($eighth_lot_bid)."\n\n";
    						
    						$email_message .= "Forename: ".clean_string($forename)."\n";
    						$email_message .= "Surname: ".clean_string($surname)."\n";
    						$email_message .= "Email: ".clean_string($email_from)."\n";
    						$email_message .= "Telephone: ".clean_string($telephone)."\n";						
    						$email_message .= "Address: ".clean_string($address)."\n";
    						 
    						 
    						// create email headers
    						$headers = 'From: '.$email_from."\r\n".
    						'Reply-To: '.$email_from."\r\n" .
    						'X-Mailer: PHP/' . phpversion();
    						@mail($email_to, $email_subject, $email_message, $headers);  
    						?>
    					 
    					If you are successful an email will be sent to you following the auction. Sale results will be uploaded to the catalogue after the auction. Please feel free to browse the rest of our website. 
    					 
    					<?php
    					}
    					?>
    I have highlighted the line in question in red

    I hope someone can help, please!

    Kind regards
    Last edited by james438; 03-16-2015 at 03:39 PM. Reason: format

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    The script looks incomplete - are there any other script files/includes that you forgot to post?

    Amongst other things, I would expect to see more lines like this which correspond to the form fields;
    Code:
    $auctiondate = $_POST['auctiondate']; // required
     $forename = $_POST['forename']; // required
     $surname = $_POST['surname']; // required
     $email_from = $_POST['email']; // required
     $telephone = $_POST['telephone']; // not required
     $address = $_POST['address']; // required
     $agreement = $_POST['agreement']; // required
    but for $first_lot_number; $first_lot_description; and $first_lot_bid; (as well as all the other lot numbers 2nd - 8th)

    I'm currently in Dronfield BTW
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    It is just a warning from php saying that you have an undefined variable ($first_lot_number) that you are trying to use clean_string() on. PHP considers this a security risk and is letting you know that there is a bit of a security risk involved in what you are doing. To see if something is set try

    Code:
    <?php
    if  (is_null($first_lot_number)) $first_lot_number='';
    ?>
    This will test to see if the value is null and if it is give it an empty value.
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Mar 2015
    Location
    Dronfield, Derbyshire
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for both your replies so quickly, yes there are other elements to the form; that was just a snippet from where the errors are coming from; this is the front-end code;

    Code:
    <form name="commissionbidform" method="post" action="verify.php">
            
                <div class="commission-panel_1">
                    
    			<fieldset>
                    <legend>Date of Auction</legend>
                    <table cellspacing="0">
                        <tr>
                            <td>Auction Date for your bids: * <input type="text" id="datepicker" name="auctiondate"></td>
                        </tr>
                    </table>
    			</fieldset>
    			
    			<fieldset>
                    <legend>Your Commission Bid(s)</legend>
                    <table cellspacing="5">
                        <tr>
                            <td>Lot No.</td>
                            <td>Brief Description</td>
                            <td>Maximum Bid <br>(Excluding Premium)</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="first_lot_number" maxlength="4" size="3" id="first_lot_number"></td>
                            <td><input type="text" name="first_lot_description" maxlength="20" size="22" id="first_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="first_lot_bid" maxlength="10" size="10" id="first_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="second_lot_number" maxlength="4" size="3" id="second_lot_number"></td>
                            <td><input type="text" name="second_lot_description" maxlength="20" size="22" id="second_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="second_lot_bid" maxlength="10" size="10" id="second_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="third_lot_number" maxlength="4" size="3" id="third_lot_number"></td>
                            <td><input type="text" name="third_lot_description" maxlength="20" size="22" id="third_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="third_lot_bid" maxlength="10" size="10" id="third_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="forth_lot_number" maxlength="4" size="3" id="forth_lot_number"></td>
                            <td><input type="text" name="forth_lot_description" maxlength="20" size="22" id="forth_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="forth_lot_bid" maxlength="10" size="10" id="forth_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="fifth_lot_number" maxlength="4" size="3" id="fifth_lot_number"></td>
                            <td><input type="text" name="fifth_lot_description" maxlength="20" size="22" id="fifth_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="fifth_lot_bid" maxlength="10" size="10" id="fifth_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="sixth_lot_number" maxlength="4" size="3" id="sixth_lot_number"></td>
                            <td><input type="text" name="sixth_lot_description" maxlength="20" size="22" id="sixth_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="sixth_lot_bid" maxlength="10" size="10" id="sixth_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="seventh_lot_number" maxlength="4" size="3" id="seventh_lot_number"></td>
                            <td><input type="text" name="seventh_lot_description" maxlength="20" size="22" id="seventh_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="seventh_lot_bid" maxlength="10" size="10" id="seventh_lot_bid">.00</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="eighth_lot_number" maxlength="4" size="3" id="eighth_lot_number"></td>
                            <td><input type="text" name="eighth_lot_description" maxlength="20" size="22" id="eighth_lot_description"></td>
                            <td>&nbsp;&pound;<input type="text" name="eighth_lot_bid" maxlength="10" size="10" id="eighth_lot_bid">.00</td>
                        </tr>
                    </table>
    			</fieldset>
                
                <fieldset>
    				<legend>Terms of Buying</legend>
    				<p><input name="agreement" type="checkbox" id="agreement" value="checkbox">I have read, understood and agree to the <br><a class="various fancybox.ajax" href="conditions.htm">Terms &amp; Conditions of Buying</a>. I understand that the Buyers Premium of 17.5% plus VAT (21% inclusive) will be added to all successful bids.</p>
    			</fieldset>
    
                </div>
            
                <div class="commission-panel_2">
                    
    				<fieldset>
                        <legend>Personal Details</legend>
                        <p><label for="forename">Forename *</label><input type="text" name="forename" id="forename" /></p>   
                        <p><label for="surname">Surname *</label><input type="text" name="surname" id="surname" /></p>    
                        <p><label for="email">Email Address *</label><input type="text" name="email" id="email" /></p>
                        <p><label for="telephone">Telephone</label><input type="text" name="telephone" id="telephone" /></p>
                        <p><label for="address">Your Address *</label><textarea name="address" id="address" rows="4" cols="10"></textarea></p>
    				</fieldset>
    				
    				<p>* denotes mandatory information</p>
    				
    				<?php
    				  require_once('recaptchalib.php');
    				  $publickey = "6LcgvecSAAAAANGXD-u-8eMllVOwnxM6-BBuVCU6"; // you got this from the signup page
    				  echo recaptcha_get_html($publickey);
    				?>
    				
    				<p class="bold">Please be aware that Commission Bids received during an auction may not be monitored.</p>
    				
                    <p><input type="image" src="pics/submit.png" alt="submit" name="submit" value="Submit"/></p>
                    
                </div>
    
    		</form>
    Funny that you're in Dronfield Beverley! From one Derbyshire folk to another! ;-)

    The problem is that the actual fields aren't sending data through email; just these fields in particular, the others are fine if this helps diagnose the issue/error?

    Thanks again
    Last edited by james438; 03-16-2015 at 10:53 PM. Reason: format

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    where is

    Code:
    $first_lot_number = $_POST['first_lot_number']; // required
    ?
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Mar 2015
    Location
    Dronfield, Derbyshire
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by james438 View Post
    where is

    Code:
    $first_lot_number = $_POST['first_lot_number']; // required
    ?
    Not in my code as they're not mandatory fields, so I have never had them checking those fields. The form previously worked on the old web provider and has suddenly stopped sending those fields through on the email

  7. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    James has highlighted what I too mentioned in my earlier post. These are not validation checks though - these lines assign variables to the posted form data so that it can be processed later on in the script.

    Your PHP error identifies that the $first_lot_number is undefined, i.e. there's no data assigned to it (and all the other lot_number, lot_description and lot_bid variables), so you need to assign *something* to it/them for the error to pass. So assign the form field data, as per the line that James posted. You will need to go through all the other lot_number, lot_description and lot_bid variables and define those in the same way.

    The form previously worked on the old web provider
    "worked" is a very loose term here. I suspect you mean that the form submitted but didn't flag any PHP errors (different PHP versions and different php.ini settings create different server behaviours, so it's possible for a script to seemingly "work" in one environment and not in another). Whether all the data was processed is another matter, and you haven't actually confirmed if the form processed all the lot/description/bid data - were they ever printed in the emails? I'd be VERY surprised if they were. Looking at the provided script, I CANT see how that could be possible.

    But the old web host is done with so we don't need to focus on what did or didn't happen in the past - you need to concentrate on making it work with your new provider, and for that to happen, you need to change your processing script so that all the variables have data assigned to them.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  8. #8
    Join Date
    Mar 2015
    Location
    Dronfield, Derbyshire
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you both, so so much - I can confirm I have added the additional lines for each field and can confirm they are all now being sent and received in emails! Happy days :-)

Similar Threads

  1. Replies: 5
    Last Post: 09-28-2012, 01:31 AM
  2. Replies: 24
    Last Post: 08-23-2012, 03:03 AM
  3. Understanding Undefined variable:
    By Webiter in forum PHP
    Replies: 6
    Last Post: 06-20-2012, 01:38 PM
  4. Undefined variable:
    By mrudul in forum PHP
    Replies: 6
    Last Post: 10-24-2011, 04:33 PM
  5. Resolved Notice: Undefined index: id on line 27
    By bokanegro in forum PHP
    Replies: 2
    Last Post: 06-06-2010, 08:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •