Solved

PHP Errors on PAge

Posted on 2015-02-24
21
65 Views
Last Modified: 2015-02-25
I have a site that I am working on.  When I go to the home page, and fill out a the form, everything is fine.  But when a colleage goes to the same site and fills out the form, he gets a PHP error:
http://23.101.151.179/

Can someone look and let me know what the issue is?  The issue was on my screen for a while cause I had a problem with my jQuery syntax.
0
Comment
Question by:rgranlund
  • 7
  • 6
  • 3
  • +4
21 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Beh, without seeing the code I can just say the same thing the error message says: the variable DB result to be undefined...
Can you show the code of the script?
0
 
LVL 6

Expert Comment

by:rjohnsonjr
Comment Utility
Can you paste the error?
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
libraries/Functions.php(688) : eval()'d code
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
Here is what I see.  Most developers would tell you that using 'eval' is potentially a very bad practice.  If done so someone can inject their own code there, they can run anything.  It can be worse than SQL injection.
PHP error
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
But why would I not be getting the error on my screen?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Because there is something about your account that is already saved and being used.  Switch to a different browser or even a different computer and check it again.
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
Please try again.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Just...

{!-- ra:000000007803329500000000137c1794 --}
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
Here is the code I have.  Maybe that will help:
<?php

class Quote {
		
	private $EE;
	private $html;
	private $start_price;
	private $bs;
	private $bike_value;
	private $adjusted_start_price;
	private $policy_number;
	

	
	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this->EE =& get_instance();
		$this->html = '';
		$this->starting_price = '';
		$this->bs = '';
		$this->bike_value = '';
		$this->adjusted_start_price = '';
		$this->policy_number = '';
	}

	
	
	 
	public function renderQuote() {

    $ip = $_SERVER['REMOTE_ADDR'];
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

	if(isset($_POST['get_quote'])) { // Handle the form.)
		$bv = $_POST['bike_value'];
		$bs = $_POST['bike_state'];
		$be = $_POST['email_value'];
							
				
		$email_query = $this->EE->db->select('email_address')
				->from('exp_bicycle_addresses')
				->where('email_address', $be)
				->limit('1')
				->get();
		
		$emthere = $email_query->result();
		
		$email_query->free_result();	
		
		
		
			
			if(!$emthere)	{

	//  START INSERT EMAIL ADDRESS INTO DB
				$email_data = array('email_address'=> $be, 'date'=> 'NOW()', 'ip'=> $ip);
				$sql_e = $this->EE->db->insert_string('exp_bicycle_addresses', $email_data);
				
				$DB->query($sql_e);
	//  END INSERT EMAIL INTO DB
			} 
			
		
//  START CREAT QUOTE
		$create_quote = ee()->db->query("SELECT id, state, pd_base_rate FROM exp_state_rates WHERE id = '$bs'");
		
		$state_data = $create_quote->result();

			
		foreach ($state_data AS $row):
			
				$div = 100;
    			$id = $row->id;
				$st = $row->state; 
		 		$br = $row->pd_base_rate;
		endforeach;
    			$rate = $bv/$div;
				$sub_price = $br * $rate;
				$sub_p = number_format($sub_price, 2, '.', ',');
				$html = $sub_price;
				$html = number_format($html, 2, '.', ',');
				$month = 12;
				$month = $html/$month;
				$month = number_format($month, 2, '.', ',');

				if ($html > 100) {
					$this->html .= '<input type="hidden" name="state_value" value="'.$html.'" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp;<span class="price-lrg">  $<span id="estimate_year" class="price">'.$html.'</span> per year</span>';
				}

				if ($html < 100)	{
					$this->html .= '<input type="hidden" name="state_value" value="100" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp; <span class="price-lrg">$100 per year</span>';
				}
				
				$this->html .= '<div style="clear:both;padding:0px 0px 13px 0px;">
	Includes Theft, Damage, Worldwide Damage Coverage, Rental Reimbursement and Roadside Assistance
</div>
<div class="clear"></div>
<h1 itemprop="name" class="product_title entry-title">Custom Bicycle Insurance From Spoke</h1>';

	 			if($html<100) {
	 				$this->starting_price = 100;	
				} else{
					$this->starting_price = $html;
				}
				
				if($sub_p < 100) {
					$this->adjusted_start_price = 100;
				} else {
				$this->adjusted_start_price = $sub_p;
				}
				
				if($bv != '') {
					$this->bike_value = $bv;	
				}
		}  //  END Form isset
		
		
//  START EMPTY QUOTE
/*This part of the code is exactly the same as the top but without the Email Entry part
 * 
 */
 
 	if(isset($_POST['get_empty_quote'])) { // Handle the form.)
		$bv = $_POST['bike_value'];
		$bs = $_POST['bike_state'];
		
//  START CREATE QUOTE

		$create_quote = $this->EE->db->select('id, state, pd_base_rate')
				->from('exp_state_rates')
				->where('id', $bs)
				->limit('1')
				->get();
		
		$state_data = $create_quote->result();
		
		$create_quote->free_result();	

	
		foreach ($state_data AS $row):
			
				$div = 100;
    			$id = $row->id;
				$st = $row->state; 
		 		$br = $row->pd_base_rate;
		endforeach;
    			$rate = $bv/$div;
				$sub_price = $br * $rate;
				$sub_p = number_format($sub_price, 2, '.', ',');
				$html = $sub_price;
				$html = number_format($html, 2, '.', ',');
				$month = 12;
				$month = $html/$month;
				$month = number_format($month, 2, '.', ',');

				if ($html > 100) {
					$this->html .= '<input type="hidden" name="state_value" value="'.$html.'" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp;<span class="price-lrg">  $<span id="estimate_year" class="price">'.$html.'</span> per year</span>';
				}

				if ($html < 100)	{
					$this->html .= '<input type="hidden" name="state_value" value="100" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp; <span class="price-lrg">$100 per year</span>';
				}
				
				$this->html .= '<div style="clear:both;padding:0px 0px 13px 0px;">
	Includes Theft, Damage, Worldwide Damage Coverage, Rental Reimbursement and Roadside Assistance
</div>
<div class="clear"></div>
<h1 itemprop="name" class="product_title entry-title">Custom Bicycle Insurance From Spoke</h1>';

				if($html<100) {
	 				$this->starting_price = 100;	
				} else{
					$this->starting_price = $html;
				}
				
				if($sub_p < 100) {
					$this->adjusted_start_price = 100;
				} else {
				$this->adjusted_start_price = $sub_p;
				}
				
				if($bv != '') {
					$this->bike_value = $bv;	
				}

				
		}  //  END Form isset
//  END EMPTY QUOTE
	}  //  END Function
	
	
	public function getHTML()	{
		return $this->html;
	}
	
	public function getPrice()	{
		return $this->starting_price;
	}
	
	public function getState()	{
		return $this->bs;
	}
	
	public function getValue()	{
		return $this->bike_value;
	}
	
	public function getBasePrice()	{
		return $this->adjusted_start_price;	
	}
	
	public function policyNumber()	{	
		$query_id = $this->EE->db->order_by('row_id', 'desc')
				->limit('1')
				->get('exp_cartthrob_order_items');
		
		$order_id = $query_id->result_array();
		
		$query_id->free_result();
		
			foreach ($order_id as $row)
			{
				$policy_number = $row['row_id'];
			}
		return $policy_number;
	}
		
	
}  //  END Class

	$q = new Quote;
	$q->renderQuote();
	$bike_state = $q->getState();
	$bike_value = $q->getValue();
	$price = $q->getPrice();
	$base_price = $q->getBasePrice();
	$policy_number = $q->policyNumber();
                                
?>

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
At line 175, you have HTML added to a variable.  In line 176, you have HTML that is not part of PHP or a variable in PHP, just plain HTML.  That should be causing an error right there.  Maybe you should turn on error reporting at the top of that page.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Author Comment

by:rgranlund
Comment Utility
I have error reporting on in that file and it reports nothing.  Also, Are you sure about those lines having error.  Those lines seem to be written correctly.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');


class Quote {
		
	private $EE;
	private $html;
	private $start_price;
	private $bs;
	private $bike_value;
	private $adjusted_start_price;
	private $policy_number;
	

	
	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this->EE =& get_instance();
		$this->html = '';
		$this->starting_price = '';
		$this->bs = '';
		$this->bike_value = '';
		$this->adjusted_start_price = '';
		$this->policy_number = '';
	}

	
	
	 
	public function renderQuote() {

    $ip = $_SERVER['REMOTE_ADDR'];
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

	if(isset($_POST['get_quote'])) { // Handle the form.)
		$bv = $_POST['bike_value'];
		$bs = $_POST['bike_state'];
		$be = $_POST['email_value'];
							
				
		$email_query = $this->EE->db->select('email_address')
				->from('exp_bicycle_addresses')
				->where('email_address', $be)
				->limit('1')
				->get();
		
		$emthere = $email_query->result();
		
		$email_query->free_result();	
		
		
		
			
			if(!$emthere)	{

	//  START INSERT EMAIL ADDRESS INTO DB
				$email_data = array('email_address'=> $be, 'date'=> 'NOW()', 'ip'=> $ip);
				$sql_e = $this->EE->db->insert_string('exp_bicycle_addresses', $email_data);
				
				$DB->query($sql_e);
	//  END INSERT EMAIL INTO DB
			} 
			
		
//  START CREAT QUOTE
		$create_quote = ee()->db->query("SELECT id, state, pd_base_rate FROM exp_state_rates WHERE id = '$bs'");
		
		$state_data = $create_quote->result();

			
		foreach ($state_data AS $row):
			
				$div = 100;
    			$id = $row->id;
				$st = $row->state; 
		 		$br = $row->pd_base_rate;
		endforeach;
    			$rate = $bv/$div;
				$sub_price = $br * $rate;
				$sub_p = number_format($sub_price, 2, '.', ',');
				$html = $sub_price;
				$html = number_format($html, 2, '.', ',');
				$month = 12;
				$month = $html/$month;
				$month = number_format($month, 2, '.', ',');

				if ($html > 100) {
					$this->html .= '<input type="hidden" name="state_value" value="'.$html.'" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp;<span class="price-lrg">  $<span id="estimate_year" class="price">'.$html.'</span> per year</span>';
				}

				if ($html < 100)	{
					$this->html .= '<input type="hidden" name="state_value" value="100" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp; <span class="price-lrg">$100 per year</span>';
				}
				
				$this->html .= '<div style="clear:both;padding:0px 0px 13px 0px;">
	Includes Theft, Damage, Worldwide Damage Coverage, Rental Reimbursement and Roadside Assistance
</div>
<div class="clear"></div>
<h1 itemprop="name" class="product_title entry-title">Custom Bicycle Insurance From Spoke</h1>';

	 			if($html<100) {
	 				$this->starting_price = 100;	
				} else{
					$this->starting_price = $html;
				}
				
				if($sub_p < 100) {
					$this->adjusted_start_price = 100;
				} else {
				$this->adjusted_start_price = $sub_p;
				}
				
				if($bv != '') {
					$this->bike_value = $bv;	
				}
		}  //  END Form isset
		
		
//  START EMPTY QUOTE
/*This part of the code is exactly the same as the top but without the Email Entry part
 * 
 */
 
 	if(isset($_POST['get_empty_quote'])) { // Handle the form.)
		$bv = $_POST['bike_value'];
		$bs = $_POST['bike_state'];
		
//  START CREATE QUOTE

		$create_quote = $this->EE->db->select('id, state, pd_base_rate')
				->from('exp_state_rates')
				->where('id', $bs)
				->limit('1')
				->get();
		
		$state_data = $create_quote->result();
		
		$create_quote->free_result();	

	
		foreach ($state_data AS $row):
			
				$div = 100;
    			$id = $row->id;
				$st = $row->state; 
		 		$br = $row->pd_base_rate;
		endforeach;
    			$rate = $bv/$div;
				$sub_price = $br * $rate;
				$sub_p = number_format($sub_price, 2, '.', ',');
				$html = $sub_price;
				$html = number_format($html, 2, '.', ',');
				$month = 12;
				$month = $html/$month;
				$month = number_format($month, 2, '.', ',');

				if ($html > 100) {
					$this->html .= '<input type="hidden" name="state_value" value="'.$html.'" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp;<span class="price-lrg">  $<span id="estimate_year" class="price">'.$html.'</span> per year</span>';
				}

				if ($html < 100)	{
					$this->html .= '<input type="hidden" name="state_value" value="100" />';
					$this->html .= '<br />Your Estimated Base Rate:  &nbsp;&nbsp; <span class="price-lrg">$100 per year</span>';
				}
				
				$this->html .= '<div style="clear:both;padding:0px 0px 13px 0px;">Includes Theft, Damage, Worldwide Damage Coverage, Rental Reimbursement and Roadside Assistance</div><div class="clear"></div><h1 itemprop="name" class="product_title entry-title">Custom Bicycle Insurance From Spoke</h1>';

				if($html<100) {
	 				$this->starting_price = 100;	
				} else{
					$this->starting_price = $html;
				}
				
				if($sub_p < 100) {
					$this->adjusted_start_price = 100;
				} else {
				$this->adjusted_start_price = $sub_p;
				}
				
				if($bv != '') {
					$this->bike_value = $bv;	
				}

				
		}  //  END Form isset
//  END EMPTY QUOTE
	}  //  END Function
	
	
	public function getHTML()	{
		return $this->html;
	}
	
	public function getPrice()	{
		return $this->starting_price;
	}
	
	public function getState()	{
		return $this->bs;
	}
	
	public function getValue()	{
		return $this->bike_value;
	}
	
	public function getBasePrice()	{
		return $this->adjusted_start_price;	
	}
	
	public function policyNumber()	{	
		$query_id = $this->EE->db->order_by('row_id', 'desc')
				->limit('1')
				->get('exp_cartthrob_order_items');
		
		$order_id = $query_id->result_array();
		
		$query_id->free_result();
		
			foreach ($order_id as $row)
			{
				$policy_number = $row['row_id'];
			}
		return $policy_number;
	}
		
	
}  //  END Class

	$q = new Quote;
	$q->renderQuote();
	$bike_state = $q->getState();
	$bike_value = $q->getValue();
	$price = $q->getPrice();
	$base_price = $q->getBasePrice();
	$policy_number = $q->policyNumber();
                                
?>

Open in new window


This is PHP on the page before, however, I don't think it is that.

<form method="post" id="get_quote" action="/index.php/store/29">
	 <input type="hidden" name="csrf_token" value="{csrf_token}" />
	<div class="bike-value">
		<input type="text" name="bike_value" id="bike_value" value="<?php if(isset($_POST['bike_value'])) {echo $_POST['bike_value'];} else {echo 'Bike Value';} ?>"  onfocus="this.value='';" {sticky}/>
	</div><div class="bike-state">
		<select name="bike_state" id="bike_state" {sticky}>
			<div><option value="" style="display:none">Choose State</option></div>
			<?php
				$query = ee()->db->query('SELECT id, state FROM exp_state_rates');
				foreach ($query->result() AS $row)
				{
					echo '<option name="bike_state" class="option-center" value="'.$row->id.'" >'.$row->state.'</option>';	
				}
			?>
		</select>
	</div><div class="email-value">
		<input type="text" name="email_value" id="email_value" value="<?php if(isset($_POST['email_value'])) {echo $_POST['email_value'];} else {echo 'Email Address';} ?>" onfocus="this.value='';" />
	</div><div class="quote-submit">
		<input class="submit" type="submit" name="submit" id="submit" value="Generate Custom Quote" />
		<input type="hidden" name="get_quote" value="TRUE" />
	</div>	
	</form>

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
What framework are you using here?
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
Expression Engine.  I had a friend in LA and a friend in Virgina run it and they had no error.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
No errors for me (Win 7 / Firefox). Worked perfectly and gave me a quote of $100 / year for my bike :)

@Dave - line 176  (and 177, 178 & 179) are just an extension of line 175, so it's not an error.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
No points for this, please, because it's certainly not an answer -- just a suggestion.  Have a look at the graphs on these pages, then kick Expression Engine to the curb.  If you need a CMS, WordPress is the right community to join.  And if you need a full framework take a serious look at Laravel.
http://trends.builtwith.com/cms
http://www.sitepoint.com/best-php-frameworks-2014/

BTW, Laravel includes all of the Symfony components.  If you do things exactly as documented in the online man pages, you can have an entire site up and running amazingly fast.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
When I used the numeric URL, I got this:

The following errors were encountered

    This form has expired. Please refresh and try again.

Return to Previous Page

The reason is because I do not accept cookies (except from sites I know).  You might want to think about whether you really need to cookie the client browser and if so, you might want to include a test to see if the client is accepting cookies.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Oops, didn't see the single quotes.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
And now I get this:

{!-- ra:000000000738d13100000000288eed7d --}
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: DB

Filename: libraries/Functions.php(688) : eval()'d code

Line Number: 69
Fatal error: Call to a member function query() on a non-object in C:\inetpub\StarrSpokeDev\system\expressionengine\libraries\Functions.php(688) : eval()'d code on line 69
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
The person running the server said it had something to do with propagation?
0
 
LVL 7

Author Closing Comment

by:rgranlund
Comment Utility
Thank you for taking the time to look into this for me.  As it would turn out, it was some sort of server error.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now