function assistance

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 4957 Views - Last Post: 29 November 2011 - 12:54 PM Rate Topic: -----

#1 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

function assistance

Posted 26 November 2011 - 12:52 PM

Hi, I wrote a simple sale tax function but for some reason it 's not working. I dont get any errors but it won't calculate the sales tax. The function is in a function library which is required. I have tried it with and without $price as an argument, but neither helped. The code is could as follows.

function TotalSalesTax()
	{
		$salesTax = .07;
		$TotalSalesTax = $price * $SalesTax;
		return $TotalSalesTax;		
	}



<tr>  
    <td></td>  
    <td>Sales Tax:  </td>
    <td><?php TotalSalesTax();?>  	</td> 
</tr>



Is This A Good Question/Topic? 0
  • +

Replies To: function assistance

#2 localhost  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 130
  • Joined: 13-December 10

Re: function assistance

Posted 26 November 2011 - 01:02 PM

Nevermind..

This post has been edited by localhost: 26 November 2011 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: function assistance

Posted 26 November 2011 - 01:03 PM

From where does $price come? I don't see it anywhere, and if it's not passed to the function then it must be global, and if it's global then it must be declared as such in the function.
Was This Post Helpful? 0
  • +
  • -

#4 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: function assistance

Posted 26 November 2011 - 01:15 PM

I put <td><?php echo $TotalSalesTax();?> </td> and it says Fatal error: Function name must be a string

$price would be coming from a form field. here's The code in its entirety.

<?php
session_start();
require_once("functions.php");
DatabaseConnection(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ordering doggy treats</title>
<style type="text/css">
#order {

	margin-right: auto;
	margin-left: auto;
}
.orderRow{ 
	padding-bottom: 50px;
}
h2 {
	text-align: center;
}

</style>
<link href="doggyTreats.css" rel="stylesheet" type="text/css" />
</head>
<body>
  
<?php        
logo();
navBar();
?>
<form action="" method="post" name="checkOut">
<table id="order">
<tr class="orderRow">  
	<td> First name:<br />
<!--	<input name="fname" type="text" size="10" maxlength="15"  value ="<?php //echo $_POST[fname];?>"/>
    <br />
    <?php //echo $errors['fname'];?></td>-->
    <td>Last name:  <br />
    <input name="lname" type="text" size="15" maxlength="30" /></td>
    <td>  Address:  <br />  
    <input name="address" type="text" size="30" /></td>
</tr>
<tr class = "orderRow">
 	<td>  City:  <br />
	      <input name="city " type="text" size="15" maxlength="20" />	</td>
	<td>   State:   <br />
          <select name = "state">  <option selected value ="Please choose a state">
			Please choose a state</option>
			<option value = "AL" >AL</option>
			<option value = "AK" >AK</option>
			<option value = "AR" >AR</option>
			<option value = "AZ" >AZ</option>
			<option value = "CA" >CA</option>
			<option value = "CO" >CO</option>
			<option value = "CT" >CT</option>
			<option value = "DE" >DE</option>
			<option value = "DC" >DC</option>
			<option value = "FL" >FL</option>
			<option value = "GA" >GA</option>
			<option value = "HI" >HI</option>						
			<option value = "IA" >IA</option>
			<option value = "ID" >ID</option>
			<option value = "IL" >IL</option>
			<option value = "IN" >IN</option>
			<option value = "KS" >KS</option>
			<option value = "KY" >KY</option>
			<option value = "LA" >LA</option>
			<option value = "MA" >MA</option>
			<option value = "ME" >ME</option>
			<option value = "MD" >MD</option>
			<option value = "MI" >MI</option>
			<option value = "MN" >MN</option>
			<option value = "MO" >MO</option>
			<option value = "MS" >MS</option>
			<option value = "MT" >MT</option>
			<option value = "NC" >NC</option>
			<option value = "ND" >ND</option>
			<option value = "NE" >NE</option>
			<option value = "NH" >NH</option>
			<option value = "NJ" >NJ</option>
			<option value = "NM" >NM</option>
			<option value = "OH" >OH</option>
			<option value = "OK" >OK</option>
			<option value = "OR" >OR</option>
			<option value = "PA" >PA</option>
			<option value = "RI" >RI</option>
			<option value = "SC" >SC</option>
			<option value = "SD" >SD</option>
			<option value = "TN" >TN</option>
			<option value = "TX" >TX</option>
			<option value = "UT" >UT</option>
			<option value = "VA" >VA</option>
 			<option value = "VT" >VT</option>
			<option value = "WA" >WA</option>
			<option value = "WI" >WI</option>
			<option value = "WV" >WV</option> 
			<option value = "WY" >WY</option>
			</select>	  </td>   
	<td>  Zip Code:<br />
          <input name="zipcode" type="text" size="5" maxlength="5" />	</td>  
</tr>  
<tr class = "orderRow">
	<td> Phone  <br />  Please include area code <br />  
	    <input name="phone" type="text" size="13" maxlength="13" />	</td>
	<td>  Fax:<br />   
    <input name="" type="text" size="13" maxlength="13" />    </td>
	<td>   Email: <br />  
	<input name="email " type="text" size="15" maxlength="30" />	</td>
</tr>
<tr class = "orderRow">  
     <td>   Please choose method of payment: <br /> 
	Check <input name="check " type="radio" value="Check " /> Money Order <input name="money " type="radio" 

value="Money order " /><br />PayPal<input name="paypal" type="radio" value="Paypal" /> </td>
</tr>
<tr>
	<td colspan = "6">	 <h2>  Pet Information </h2></td>
</tr>
     <tr>
	  <td>  Name: <br /> 
	      <input name="petName" type="text" size="10" maxlength="20" />	  </td>  
	<td>   Age: <br />
	<select name="age">  
<?php
  for ($age =1; $age <=20; $age ++)
 	{
		print "<option value=\"age\">  $age</option>"; 
	}
?>   
</select></td>   
<td>   Breed:<br />
	<select name = "breed">  <option selected value ="Please choose a breed">
			Please choose a breed </option>
			    <option value = "I don't know" >I don't know </option>
				<option value = "Affernpincher" >Affernpincher </option>
				<option value = "Afghan Hound" >Afghan Hound </option>
				<option value = "Airedale Terrier" > Airedale Terrior</option>
				<option value = "Akita" >  Akita </option>
				<option value = "Alaskan Malamute" >  Alaskan Malamute </option>
				<option value = "Standard American Eskimo Dog"> Standard American Eskimo Dog</option>
				<option value = "Miniature American Eskimo Dog">Miniature American Eskimo 		
                                 Dog</option>
				<option value = "Toy American Eskimo Dog"> Toy American Eskimo Dog</option>
				<option value = "American Foxhound" >  American Foxhound</option>
				<option value = "American Staffordshire Terrier" >  American Staffordshhire                                 Terrier</option>
				<option value = "American Water Spaniel" > American Water Spaniel</option>
				<option value = "Australian Shepherd Dog">  Anatolian Shepherd Dog </option>
				<option value = "Australian Cattle Dog">  Australian Cattle Dog</option>
				<option value = "Australian Shepherd">  Australian Shepherd </option>
				<option value = "Australian Terrier" >  Australia Terrier</option>
				<option value = "Basenji" >  Basenji</option>
				<option value = "Basset Hound" >  Basset Hound </option>
				<option value = "Beagle" >  Beagle</option>
				<option value = "Bearded Collie" >  Bearded Collie</option>
				<option value = "Beauceron" >  Beauceron </option> 
				<option value = "Bedington Terrier">  Bedington Terrier</option>
				<option value = "Belgin Malinois"> Belgin Malinois</option>
				<option value = "Belgian Sheepdog">  Belgian Sheepdog</option>
				<option value = "Belgian Tervuren">  Belgian Tervuren</option>
				<option value = "Bernese Mountain Dog">  Bernese Mountain Dog</option> 
				<option value = "Bichon Frise">  Bichon Frise</option>
				<option value = "Black and Tan Greyhound" >  Black and Tan Greyhound</option>
				<option value = "Black Russian Terrier" >  Black Russian Terrier</option>
				<option value = "Bloodhoung" >  Bloodhound</option>
				<option value = "Border Collie" > Border Collie</option>
				<option value = "Border Terrier"> Border Terrier</option>
				<option value = "Borzoi">  Borzoi</option>
				<option value = "Boston Terrier">  Boston Terrier</option>
				<option value = "Bouvier des Flandres">  Bouvier des Flandres</option>
				<option value = "Boxer">  Boxer</option>
				<option value = "Briard">  Briard</option>
				<option value = "Brittany" >  Brittany</option>
				<option value = "Brussels Griffon" >  Brussels Griffon</option>
				<option value = "Bulldog" > Bulldog</option>
				<option value = "Bullmastiff" > Bullmasttiff</option>
				<option value = "Bull Terrier" >  Bull Terrier</option>
				<option value = "Cairn Terrier" >  Cairn Terrier</option>
				<option value = "Canaan Dog" >  Canaan Dog</option>
				<option value = "Cardigan Welsh Corgi" >  Cardigan Welsh Corgi</option>
				<option value = "Cavalier King Charles Spaniel" >Cavalier King Charles 
                             Spaniel</option>
				<option value = "Chesepeake Bay Retriever" >Chesapeake Bay Retriever</option>
				<option value = "Chilauhua" > Chilauhua</option>
				<option value = "Chinese Created" >  Chinese Crested</option>
				<option value = "Chinese Shar-Pei" >  Chinese Shar-Pei</option> 
				<option value = "Chow Chow" >  Chow Chow</option>
				<option value = "Clumber Spaniel" >  Clumber Spaniel</option>
				<option value = "Cocker Spaniel" >  Cocker Spaniel</option>
				<option value = "Collie" >  Collie</option>
				<option value = "Curly-Coated Retriever" >  Curly-Coated Retriever</option>
				<option value = "Dachshound" >  Dachshund</option>
				<option value = "Dalmation" > Dalmation</option>
				<option value = "Dandle Dimonnt" > Dandie Dinmont Terrier</option>
				<option value = "Doberman Pincher" >  Doberman Pincher</option>
				<option value = "Dogue de Bordeaux" > Dogue de Bordeaux</option>
				<option value = "English Cocker Spaniel" >  English Cocker Spaniel</option>  
				<option value = "English Foxhound" >  English Foxhound</option>
				<option value = "English Setter" >  English Setter</option>
				<option value = "English Springer" > English Springer</option>
				<option value = "English Toy Spaniel" >  English Toy Spaniel</option>
				<option value = "Field Spaniel" > Field Spaniel</option>
				<option value = "Finnish Spitz" >  Finnish Spitz</option>
				<option value = "Flat-Coated Retriever" >  Flat-Coated Retriever</option>
				<option value = "French Bulldog" >  French Bulldog</option>
				<option value = "German Shepherd Dog" > German Shepherd Dog</option>
				<option value = "German Shorthaired Pointer">German Shorthaired Pointer</option>
				<option value = "German Wirehaired Pointer" >  German Wirehaired Pointer </option>
				<option value = "Giant Schnauzer" > Giant Schnauzer</option>
				<option value = "Glen of Imaal Terrier" >  Glen of Imaal Terrier</option>
				<option value = "Golden Retriever" > Golden Retriever</option>
				<option value = "Gorden Setter" > Gorden Setter</option>
				<option value = "Great Dane" > Great Dane</option>
				<option value = "Greater Swiss Mountain Dog" > Greater Swiss Mountain Dog</option>
				<option value = "Great Pyrenees" > Great Pyrenees</option>
				<option value = "Greyhound" > Greyhound</option>
				<option value = "Harrier"  > Harrier</option>
				<option value = "Havanese" >  Havanese</option>
				<option value = "Ibizen Hound" > Ibizen Hound </option>
				<option value = "Irish Setter" >  Irish Setter</option>
				<option value = "Irish Terrier" > Irish Terrier</option>
				<option value = "Irish Water Spaniel"> Irish Water Spaniel</option>
				<option value = "Irish Wolfhound" >  Irish Wolfhound</option>
				<option value = "Italian Greyhound">  Italian Greyhound</option>
				<option value = "Jack Russell Terrier" >  Jack Russell Terrier</option>
				<option value = "Japanese Chin" >  Japanese Chin</option>
				<option value = "Keeshound" >  Keeshound</option>
				<option value = "Kerry Blue TErrier" >  Kerry Blue Terrier</option>
				<option value = "Komondor" > Komondor</option>
				<option value = "Kuvasz" >  Kuvasz</option>
				<option value = "Labradar Retriever" >  Labrador Retriever</option>
				<option value = "Lakeland Terrier" >  Lakeland Terrier</option>
				<option value = "Lhasa Apso" >  Lhasa Apso</option>
				<option value = "Lowchen" >  Lowchen</option>
				<option value = "Maltese" >  Maltese</option>
				<option value = "Standard Manchester Terrier" > Standard Manchester Terrier</option>
				<option value = "Mastiff" >  Mastiff</option>
				<option value = "Miniature Bull Terrier" >  Miniature Bull Terrier</option>
				<option value = "Miniature Pinche" > Miniature Pinscher</option>
				<option value = "Miniature Poodle" > Miniature Poodle</option>
				<option value = "Miniature Schnauzer" >Miniature Schnauzer</option>
				<option value = "Mutt" >Mutt</option>
				<option value = "Neopolitan Mastiff" >Neopolitan Mastiff</option>
				<option value = "Newfoundland"> Newfoundland </option>
				<option value = "Newfolk Terrier" >Norfolk Terrier</option>
				<option value = "Norwegian Elkhound" > Norwegian Elkhound</option>
				<option value = "Norwich Terrier" > Norwich Terrier</option>
				<option value = "Nova Scotia Duck Tolling Retriever"> Nova Scotia Duck 	   Tolling Retriever</option>
				<option value = "Old English Sheepdog">Old English Sheepdog</option>
				<option value = "Otterhound" > Otterhound</option>
				<option value = "Papillon" >Papillon</option>
				<option value = "Parson Russell Terrier" > Parson Russell Terrier</option>
				<option value = "Pekingese" >Pekingese</option>
				<option value = "Pembroke Welsh Corgi" >Pembroke Welsh Corgi</option>
				<option value = "Petit Basset Griffon Vendeen">Petit Basset Griffon Vendeen</option>
				<option value = "Pharch Hound" >Pharoh Hound</option>
				<option value = "Plott" > Plott</option>
				<option value = "Pointer" > Pointer </option>
				<option value = "Polish Lowland Sheepdog" >Polish Lowland Sheepdog</option>
				<option value = "Pomeranian" > Pomeranian</option>
				<option value = "Portuguese Water Dog" >Portuguese Water Dog </option>
				<option value = "Pug" >Pug</option>
				<option value = "Pull" >Puli</option>
				<option value = "Rhodesian Ridgeback" >Rhodesian Ridgeback</option>
				<option value = "Rottweiler" >Rottweiler</option>
				<option value = "ASaint Bernard" > Saint Bernard</option>
				<option value = "Saluki" > Saluki</option>
				<option value = "Samoyed" >Samoyed</option>
				<option value = "Schipperke" >Schipperke</option>
				<option value = "Scottish Doverhound" >Scottish Deerhound</option>
				<option value = "Scottish Terrier" >Scottish Terrier</option>
				<option value = "Sealyham Terrier" >Sealyham Terrier</option>
				<option value = "Shetland Sheepdog" >Shetland Sheepdog</option>
				<option value = "Shiba Inu" >Shiba Inu</option>
				<option value = "Shih Tzu" >Shih Tzu</option>
				<option value = "Siberian Husky" >Siberian Husky</option>
				<option value = "Silky Terrier" >Silky Terrier</option>
				<option value = "Skye Terrier" >Skye Terrier </option>
				<option value = "Smooth Fox Terrier" >Smooth Fox Terrier</option>
				<option value = "Soft Coated Wheaten Terrier" >Soft Coated wheaten Terrier</option>
				<option value = "Spinone Italiano" >Spinone Italiano</option>
				<option value = "Staffordshire Bull Terrier" >Staffordshire Bull Terrier</option>
				<option value = "Standard Poodle" >Standard Poodle</option>
				<option value = "Standard Schnauer" > Standard Schnauzer</option>
				<option value = "Suseex Spaniel"  >Sussex Spaniel</option>
				<option value = "Swedish Vallhound" >Swedish Vallhund</option>
				<option value = "Tibertan Mastiff" >Tibetan Mastiff</option>
				<option value = "Tibertan Spaniel" >Tibetan Spaniel</option>
				<option value = "Tibetan Terrier" >Tibetan Terrier </option>
				<option value = "Toy Fox Terrier" >Toy Fox Terrier </option>
				<option value = "Toy Manchester Terrier" >Toy Manchester Terrier </option>
                <option value = "Toy Poodle" >Toy Poodle</option>
				<option value = "Vizela" >Vizela</option>
				<option value = "Weimaraner" >Weimaraner</option>
				<option value = "Welsh Springer Spaniel" >Welsh Springer Spaniel</option>
				<option value = "Welsh Terrier" >Welsh Terrier </option>
				<option value = "West Highland White Terrier" >West Highland White Terrier </option>
				<option value = "Whippet" >Whippet</option>
				<option value = "Wire Fox Terrier" >Wire Fox Terrier </option>
				<option value = "Wirehaired Pointing Griffon" >Wirehaired Pointing Griffon</option>
				<option value = "Yorkshire Terrier">Yorkshire Terrier 	</option>
                	</select>	</td>
</tr>
<tr>
	<td>Nutritional Needs:</td>
	<td><textarea name="nutritionalNeeds" cols="17" rows="5"></textarea>	</td>
</tr>
<tr>
	<td>Special Instructions</td>
	<td><textarea name="specialInstructions" cols="17" rows="5"></textarea></td>
</tr>
<tr>
	<td colspan = "6"><h2>Order Information</h2></td>
</tr>
<tr>
    <td><strong>Product Name</strong></td>
    <td>&nbsp;</td>
    <td><strong>Price </strong></td>
</tr>

<?php
DatabaseConnection();  

  $query = "SELECT * FROM treats"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0;

    
		$total=0;
        while ($row = mysql_fetch_array($result_set))
        {
			if($_POST["quantity".$row["product_id"]]!="")
			{
?>
<tr>  
	<td>  <?php echo $row["product_title"];?></td>
    <td><?php echo $_POST["quantity".$row["product_id"]];?> x <?php echo $row["price"];?></td>
	<td align="right"> $<?php echo number_format($_POST["quantity".$row["product_id"]] * $row["price"],2); ?></td>
</tr>
<?php
		}
 
$total += number_format($_POST["quantity".$row["product_id"]] * $row["price"],2);
}
?>
<tr>
  <td></td>
  <td><strong>Total</strong></td>
  <td align="right"><strong>$<?php echo number_format($total,2); ?></strong></td>
</tr>
<tr>  
    <td></td>  
    <td>Sales Tax:  </td>
    <td><?php echo $TotalSalesTax();?>  	</td> 
</tr>
<tr>
	<td></td>
    <td>Subtotal:  </td> 
</tr>
<tr>  
	<td></td>	
    <td>Shipping:  </td>
    <td> 	</td>
</tr>
<tr>  
	<td>  </td>
    <td>  Total:  </td>
    <td> 	</td>
</tr>
<tr>
<td></td>   
	<td><input name="reset" type="submit" value="Cancel Order" /> </td><td> <input name="Submit" type="submit" value="Order Treats!" /></td>
</tr>
</table>
</form>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#5 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: function assistance

Posted 26 November 2011 - 01:22 PM

Dollar signs are for variables, not functions.

<?php echo TotalSalesTax(); ?> 



But you will have to send price as a parameter, or it won't work.

This post has been edited by Duckington: 26 November 2011 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,590
  • Joined: 08-August 08

Re: function assistance

Posted 26 November 2011 - 02:56 PM

PHP, CSS, and HTML in the same file! Why not throw in some Javascript so you can really make it hard to read? I won't try to read that mess, but your function in post #1 should always return zero because $salesTax is not the same variable as $SalesTax because PHP variables are case sensitive.
Was This Post Helpful? 1
  • +
  • -

#7 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: function assistance

Posted 26 November 2011 - 07:18 PM

for your information, the CSS you see is for this page ONLY!
Was This Post Helpful? 0
  • +
  • -

#8 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: function assistance

Posted 26 November 2011 - 07:34 PM

okay, I have changed a few things but I'm still getting a sales tax of 0.

<tr>  
    <td></td>  
    <td>Sales Tax:  </td>
    <td><?php echo TotalSalesTax($price);?>  	</td> 
</tr>




function TotalSalesTax($price)
	{
		$salesTax = .07;
		$TotalSalesTax = $price * $salesTax;
	    number_format($TotalSalesTax, 2);	
		return $TotalSalesTax;		
	}


Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,590
  • Joined: 08-August 08

Re: function assistance

Posted 26 November 2011 - 07:44 PM

This shows 7 for me:
<?php
echo TotalSalesTax(100);

function TotalSalesTax($price)
	{
		$salesTax = .07;
		$TotalSalesTax = $price * $salesTax;
	    number_format($TotalSalesTax, 2);	
		return $TotalSalesTax;		
	}
?>

So I'd have to assume that your $price is 0.
Was This Post Helpful? 1
  • +
  • -

#10 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: function assistance

Posted 26 November 2011 - 07:53 PM

Oh, wait, could it be because the price is coming from a database?

View PostCTphpnwb, on 27 November 2011 - 02:44 AM, said:

This shows 7 for me:
<?php
echo TotalSalesTax(100);

function TotalSalesTax($price)
	{
		$salesTax = .07;
		$TotalSalesTax = $price * $salesTax;
	    number_format($TotalSalesTax, 2);	
		return $TotalSalesTax;		
	}
?>

So I'd have to assume that your $price is 0.

Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,590
  • Joined: 08-August 08

Re: function assistance

Posted 26 November 2011 - 08:23 PM

It looks to me like you're not passing a price to the function. You really need to concentrate on making your code readable. Separate the HTML and PHP, and use PHP to generate repetitive HTML like your select options. If it's readable you'll have a lot less trouble getting it to work.
Was This Post Helpful? 1
  • +
  • -

#12 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: function assistance

Posted 26 November 2011 - 08:26 PM

That does not answer the question
Was This Post Helpful? 0
  • +
  • -

#13 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: function assistance

Posted 27 November 2011 - 11:03 AM

The problem is, according to the code you provided, you're passing $price to your function, but prior to that function call, you've never set it, so PHP converts it to an integer when you try to do math with it. The integer representation of NULL in PHP is 0, so you'll get 0 from your function every time until you pass a price to it.
Was This Post Helpful? 1
  • +
  • -

#14 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,590
  • Joined: 08-August 08

Re: function assistance

Posted 27 November 2011 - 11:17 AM

View PostValek, on 27 November 2011 - 02:03 PM, said:

The problem is, according to the code you provided, you're passing $price to your function, but prior to that function call, you've never set it, so PHP converts it to an integer when you try to do math with it. The integer representation of NULL in PHP is 0, so you'll get 0 from your function every time until you pass a price to it.

Hence:

View PostCTphpnwb, on 26 November 2011 - 11:23 PM, said:

It looks to me like you're not passing a price to the function.

from my previous post. The rest of that post still applies. Silly problems like this arise when you can no longer keep track of the code you've written.
Was This Post Helpful? 1
  • +
  • -

#15 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: function assistance

Posted 27 November 2011 - 11:20 AM

My apologies, CT, I didn't see that. Been up for about 24 hours now, so I'm missing things here and there.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3