Jump to content

error, can you figure out the problem?


jwk811

Recommended Posts

this is my shipping calculator.. im getting an error with the unexpected $ and i dont see what the problem is.. i hate those errors because they're not at all specific and the line is always told to you as the last line.. something its because i forget {} or ''... can you figure it out? thanks!

 

<?php

require_once 'config.php';
require_once 'database.php';


function findShippingPrice($section, $service, $method, $transit, $weight)
{

$weight_up = round_up_ten($weight);
$weight_down = round_dwn_ten($weight);
$weight_ones =  floor($weight)%10;  

$weight_limit = 70;
if($weight / $weight_limit > 1){

$weight_floor = floor($weight / $weight_limit);

$sql    = "SELECT price FROM tbl_shipping WHERE section = '$section' AND service = '$service' AND method = '$method' AND transit = '$transit' AND weight = '$weight_limit'";
$result = dbQuery($sql);

if(dbNumRows($result) == 1){

	$row = dbFetchAssoc($result);
	extract($row);
}
$price_full = $price * $weight_floor;
}


$sql    = "SELECT price FROM tbl_shipping WHERE section = '$section' AND service = '$service' AND method = '$method' AND transit = '$transit' AND weight = '$weight_up'";
$result = dbQuery($sql);

if(dbNumRows($result) == 1){

	$row = dbFetchAssoc($result);
	extract($row);

	$price_up = $price;
}
else{
	return 'N/A';
}

$sql    = "SELECT price FROM tbl_shipping WHERE section = '$section' AND service = '$service' AND method = '$method' AND transit = '$transit' AND weight = '$weight_down'";
$result = dbQuery($sql);

if(dbNumRows($result) == 1){

	$row = dbFetchAssoc($result);
	extract($row);

	$price_down = $price;
}
else{
	$price_down = 0;
}

$estimated_cost = find_between($weight_up, $weight_down, $weight_ones);

if(isset($price_full)){
	$estimated_cost = $estimated_cost + $price_full;
}

return $estimated_cost;
}

function find_between($up, $down, $ones){
{
$num = $up - $down;
$num = $num % 10;
$num = $num * $ones;
$num = $num + $down;
return $num;
}

function round_up_ten($num)
{
$mod = $num % 10;
$add = 10 - $mod;
$num += $add;
return $num;
}

function round_dwn_ten($num)
{
$mod = $num % 10;
$add = 10 - (10 - $mod);
$num -= $add;
return $num;
}
?>

Link to comment
Share on other sites

This line:

 

<?php
$weight_ones =&#160; floor($weight)%10;&#160; 
?>

You you need to echo those spaces or put them in quotes. I believe thats what is giving errors

<?php
$weight_ones = "&#160;".floor($weight) % 10."&#160"; 
?>

 

Or however it is supposed to be formatted... I'm not sure what you are trying to do. I guess thats a modulus 10? If it is, you can't throw the spaces in next to it. Those have to come when you actually output the variable.

 

Then in the $sql variables, I don't understand the usage with the nbsp next to the actual variable name.

<?php $sql&#160; &#160; = "..."; ?>

to...

<?php
$sql = "..."; ?>

Link to comment
Share on other sites

jwk, you need to get yourself an editor which can fix these problems for you :)  They are too basic to be wasting time on.

 

Here's one line with a problem

 

if(dbNumRows($result) == 1){

 

The second ) is missing.  An editor which finds matching () would have shown you the problem.  Vim is one such editor (there's many others I'm sure).

 

The most common reason I get the "$" error is missing out a closing } .. when I get the error, I just ask Vim for the matching pairs of {}, and see which one is missing.

Link to comment
Share on other sites

its not just down to the program as well. you can get a good program that spots these for you but thats why you test your code regularly, after each edit to see if you get any errors. then you no the exact location the error could be. and its just one of those things that you have to keep an eye on.

Link to comment
Share on other sites

This line:

 

<?php
$weight_ones =&#160; floor($weight)%10;&#160; 
?>

You you need to echo those spaces or put them in quotes. I believe thats what is giving errors

<?php
$weight_ones = "&#160;".floor($weight) % 10."&#160"; 
?>

 

Or however it is supposed to be formatted... I'm not sure what you are trying to do. I guess thats a modulus 10? If it is, you can't throw the spaces in next to it. Those have to come when you actually output the variable.

 

Then in the $sql variables, I don't understand the usage with the nbsp next to the actual variable name.

<?php $sql&#160; &#160; = "..."; ?>

to...

<?php
$sql = "..."; ?>

i actually dont know how that stuff got in there lol.. its not in my code but shows up on this website when i post it, weird

jwk, you need to get yourself an editor which can fix these problems for you :)  They are too basic to be wasting time on.

 

Here's one line with a problem

 

if(dbNumRows($result) == 1){

 

The second ) is missing.  An editor which finds matching () would have shown you the problem.  Vim is one such editor (there's many others I'm sure).

 

The most common reason I get the "$" error is missing out a closing } .. when I get the error, I just ask Vim for the matching pairs of {}, and see which one is missing.

 

um.. i dont see another ) missing?

 

and my server usually picks up those errors just sometimes it doesnt and i have to find it myself..

Link to comment
Share on other sites

yeah.. i just got rid of the bottom little functions and it came out okay.. so what it wrong with those?

 

function find_between($up, $down, $ones){
{
$num = $up - $down;
$num = $num % 10;
$num = $num * $ones;
$num = $num + $down;
return $num;
}

function round_up_ten($num)
{
$mod = $num % 10;
$add = 10 - $mod;
$num += $add;
return $num;
}

function round_dwn_ten($num)
{
$mod = $num % 10;
$add = 10 - (10 - $mod);
$num -= $add;
return $num;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.