This is a simple problem but for some reason it is eluding me...
I have a form that has text fields and check boxes, the function checks the
form, counts words, strips the slashes, then based on the number of words
and number of checkboxes selected calculates a cost... I have added 4 new
checkboxes and when i try to do the calculation $total *= $section; it will
not count the four check boxes and multiply the total by the number
selected... here is the code, any help would be great:
$papers = $box1 + $box2; //checkboxes
$section = $box3 + $box4 + $box5 + $box6; // new ones i have added that
won't work
$ad2 = $ad; //ad for viewer
$ad = trim($ad); //trim spaces from entry

$ad = ereg_replace ("\"", "&q&", $ad);  # prevents an error when sending $ad
through an HTML form
$ad = ereg_replace ("'", "&a&", $ad);  # prevents a mysql error
$ad = ereg_replace ("%", "&p&", $ad); #prevents a mysql error
$ad = ereg_replace ("\\\\", "&bs&", $ad); #prevents a mysql error
# splits the ad into an array called $words
$words = split(" ", $ad);

# counts the number of expressions in the array
$num = count($words);

# variable used to check how many of the expressions are really spaces
$count2 = 0;

for($i = 0; $i < $num; $i++){ # determines if any variables are empty and if
they are $count goes up one to determine how many spaces there are in the
 if ($words[$count2] == "" ){
 $count = $count + 1;
$count2 = $count2 + 1;

$num = $num - $count; #gets the new number of words

$price = 5.00;

if ($num > 10) { # if the users ad has more than 10 words in it than
$quarters = the extra words times .20
 $subtractor = $num - 10;
 $quarters = $subtractor * .20;
$subtotal = $price + $quarters; # price plus the number of words over 10
$total = $papers * $subsubtotal; # new price multiplied by number of papers
$total *= $weeks * $section; # this is where I am stuck, doesnt calculate
the new checkboxes
$total = sprintf ("%01.2f", $total);

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to