PHP - how to calculate % and how to stop form from auto submit.

Asked By Olusegun A. on 12-Oct-09 08:59 AM
Hello Success-Oriented People,

I want to calculated 90% and a particular amount am having in my database. I named the column of the amount in the database [b]abalance[/b]. this is the code i tried but its not working,

$ninetypercent=(90/100*'$abalance');

What is the way out?

Secondly, am having a form where members can edit their account. When the member clicked on edit profile from his/her welcome page, the below page will be opened. my problem is that starting the form with teh IF function in order to stop the form from submitting automatically, whenever the page is loaded, the page will not echo out the members informations but if i removed the IF function, all the members information will be display but the form will be submitting itself automatically.

<?php

if(!empty($_POST[Submit]))
{
include("customersinfodb.php");
$id=$_SESSION[id];
$check=mysql_query("select * from clients where id='$id'");
while($look=mysql_fetch_array($check))
{
$id=$look[id];
$ano=$look[ano];
$fname=$look[fname];
$mname=$look[mname];
$lname=$look[lname];
$address=$look[address];
$address2=$look[address2];
$city=$look[city];
$state=$look[state];
$country=$look[country];
$pcode=$look[pcode];
$gender=$look[gender];
$pno=$look[pno];
$pno2=$look[pno2];
$atype=$look[atype];
$currency=$look[currency];
$status=$look[status];
}
$nfname=$_POST[fname];
$nmname=$_POST[mname];
$nlname=$_POST[lname];
$naddress=$_POST[address];
$naddress2=$_POST[address2];
$ncity=$_POST[city];
$nstate=$_POST[state];
$ncountry=$_POST[country];
$npcode=$_POST[pcode];
$ngender=$_POST[gender];
$npno=$_POST[pno];
$npno2=$_POST[pno2];
$natype=$_POST[atype];
$ncurrency=$_POST[currency];
$nstatus=$_POST[status];
$update=mysql_query("update clients set fname='$nfname', mname='$nmname', lname='$nlname', address='$naddress', address2='$naddress2', city='$ncity', state='$nstate', country='$ncountry', pcode='$npcode', gender='$ngender', pno='$npno', pno2='$npno2', atype='$natype', currency='$ncurrency', status='$nstutas' where ano='$ano'");
if(!$upload)
echo "The Information is not updated, try again.<br>";
else
echo "The Information is updated successfully.<br>";
}
  ?>
what can i do to this form?

Regards,
adsegzy

reply - Deepak Sonawane replied to Olusegun A. on 12-Oct-09 09:12 AM

Hi,

Here is function in php that you can use to calculate percentage:

function percent($num_amount) {
$count1 = 90*$num_amount ;
$count2 = $count1 / 100;
$count = number_format($count2, 0);
echo $count;
}




ffunction percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;
}unction percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;
}