jwk811 Posted February 20, 2007 Share Posted February 20, 2007 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; } ?> Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 This line: <?php $weight_ones =  floor($weight)%10;  ?> You you need to echo those spaces or put them in quotes. I believe thats what is giving errors <?php $weight_ones = " ".floor($weight) % 10." "; ?> 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    = "..."; ?> to... <?php $sql = "..."; ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted February 20, 2007 Share Posted February 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 Textpad is another good one Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 20, 2007 Share Posted February 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted February 20, 2007 Author Share Posted February 20, 2007 This line: <?php $weight_ones =  floor($weight)%10;  ?> You you need to echo those spaces or put them in quotes. I believe thats what is giving errors <?php $weight_ones = " ".floor($weight) % 10." "; ?> 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    = "..."; ?> 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.. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted February 20, 2007 Author Share Posted February 20, 2007 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; } Quote Link to comment Share on other sites More sharing options...
jwk811 Posted February 20, 2007 Author Share Posted February 20, 2007 narrowed it down to this function right here which has the problem.. but i still dont see the problem... function find_between($up, $down, $ones){ { $num = $up - $down; $num = $num % 10; $num = $num * $ones; $num = $num + $down; return $num; } Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 It has two {{ function find_between($up, $down, $ones){ { Quote Link to comment Share on other sites More sharing options...
jwk811 Posted February 20, 2007 Author Share Posted February 20, 2007 oh lol.. thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.