Hey there,

I'm facing a problem with a calculator on my site, you can see it here: http://axa.seomena.com/fr/calculez-vos-primes/calculez-vos-primes-assurances-medicales

The problem is, when you choose the "number of family" whether you're a family of 1 or a family of 6 and more, (in the next step) if you choose anything but "Class SP" the calculation will work, but if you choose "Class SP" in the "Montant Police(US$)" cell instead of printing a value number it just says "NAN", I donno what's the problem with it but I'm assuming it's something to do with the php or some missing values in phpmyadmin.

If you notice in the image attached below that when "Class_type_id" is equal to "5" the "family_type_id" is always equal to 0. class_type_id 5 represent the "Class SP".

Here is the code

ksort($counter);
    foreach ($counter as $nb=>$data){
       
        //echo $age_range_id[$nb].'--'.$class_type_id[$nb].'--'.$nssf[$nb].'--'.$amb[$nb].'--'.$med[$nb].'--'.$doc[$nb].' ||||||| ';
        //echo $nb;
        //if((!$age_range_id[$nb-1])||(!$class_type_id[$nb]))continue;
        if($nssf[$nb]=="on")$add="and nssf=1";
        else $add="and nssf=0";
       
        if(($amb=="on") && ($age_range_id[$nb-1]))$get_amount_amb=id2fields("amb_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb-1]."");
        if(($med=="on") && ($age_range_id[$nb-1]))$get_amount_med=id2fields("pre_med_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb-1]."");
        if(($doc=="on") && ($age_range_id[$nb-1]))$get_amount_doc=id2fields("doc_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb-1]."");
   
        //echo $get_amount_amb.'~~~'.$get_amount_med.'~~~'.$get_amount_doc.'<br>';
       
       
        if($class_type_id[$nb]<>5){ // NO class SP
       
            if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
                "age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." and family_type_id=$family_type_id $add");
       
        }
        else { // Class SP
           
            if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
                    "age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." $add");

        }
        $sum_amount=$get_amount+$get_amount_amb+$get_amount_med+$get_amount_doc;   
        /*echo "<b>".($get_amount?$get_amount:"NaN").($get_amount_amb?"- $get_amount_amb ":"").($get_amount_med?" - $get_amount_med ":"").($get_amount_doc?" - $get_amount_doc total : ----> $sum_amount ":"")."</b>";
            echo "<br>";*/
       
    //echo "==>".$age_range_id[$nb-1].'<br>';   
       
    if($age_range_id[$nb-1]){       
            echo "<tr>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".$nb."</td>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".($get_amount?number_format($get_amount,2,'.',','):"NAN")."</td>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".($get_amount_amb?$get_amount_amb:"&nbsp; ")."</td>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".($get_amount_med?$get_amount_med:"&nbsp; ")."</td>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".($get_amount_doc?$get_amount_doc:"&nbsp; ")."</td>
                        <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".number_format($sum_amount,2,'.',',')."</td>
                        <input type='hidden' name='amnt[$nb]' value='$get_amount'/>
                        <input type='hidden' name='amnt_amb' value='$get_amount_amb'/>
                        <input type='hidden' name='amnt_med' value='$get_amount_med'/>
                        <input type='hidden' name='amnt_doc' value='$get_amount_doc'/>
                        <input type='hidden' name='sum[$nb]' value='$sum_amount'/>
                        <input type='hidden' name='nb[$nb]' value='$nb'/>
                </tr>";   
               
            $total+=$sum_amount;
        }
           
    }
    echo "<tr>
                <td align='right' colspan='5' id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'><b> &nbsp;&nbsp;&nbsp; Total des primes:</b></td>
                <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'><b>".number_format($total,2,'.',',')."</b></td>
         </tr>
         ";
   
    echo "</table></center><br><br>";
   
    echo '
            <table>
                    <tr><td style="font-size: 8pt; line-height:11pt; font-family:tahoma" colspan="2" id="seperator">Veuillez remplir les informations suivantes pour qu’un de nos agents vous contacte. </td></tr>
                    <tr><td style="font-size: 8pt; line-height:11pt; font-family:tahoma">Nom :</td><td align="left"> <input type="text" name="nom"/></td>
                    </tr>
                    <tr>
                        <td style="font-size: 8pt; line-height:11pt; font-family:tahoma">Pr&eacute;nom :</td><td align="left"> <input type="text" name="prenom"/></td>
                    </tr>
                    <tr>
                        <td style="font-size: 8pt; line-height:11pt; font-family:tahoma">No.Cellulaire :</td><td align="left"> <input type="text" name="phone"/></td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="font-size:12px; font-family:tahoma" width="60%" id="lasttdpadd" colspan="2">
                            <input type="submit" value="Soumettre" name="submit"/>
                            <input type="hidden" value="true" name="sendmail"/>
                            <input type="hidden" value="'.$total.'" name="total"/>
                        </td>
                    </tr>
                </table><br><br><br><br><br><br><br><br><br><br><br><br><br></form>
                ';
    exit;
               
}
           
if((($_POST["step"]==1)&&($_POST["sbm"]=='Étape suivante'))||($_POST["class_type_id"])){
    //printR($_POST);

Thanks.

I think the problem is here:

if($class_type_id[$nb]<>5){ // NO class SP
		
			if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
				"age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." and family_type_id=$family_type_id $add");
		
		}
		/*else { // Class SP
			
			if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
					"age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." and family_type_id=$family_type_id $add");

		}*/
		else { // Class SP
						
						$get_amount=id2fields("policy","amount",
								"age_range_id=".$age_range_id[$nb]." and class_type_id=".$class_type_id[$nb]." and family_type_id=".$family_type_id[$nb]." $add");
			
					}

As you can see if $class_type_id is not equal to 5, it has a different function and I think the function is wrong. I tried to use 2 different ones with no luck so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.