douyi0902 2013-12-05 08:57
浏览 46

SQL / PHP计算器

Im trying to make a little calculator with input given by a person, multiplying and adding these answers with some variables declared in php. But I can't get it to work properly.

What is wrong with this script? The writing to database part from the form works correctly. But when it directs to the output screen, the calculations don't really work.

mysql_connect("localhost" , "root" , "DM3") or die (MySQL_error());
mysql_select_db("calculator");

$order = "INSERT INTO calculator (nineholes , eightteenholes , hcp , club , academy , locker , rainflex ) VALUES ('$_POST[nineholes]','$_POST[eightteenholes]','$_POST[hcp]','$_POST[club]','$_POST[academy]','$_POST[locker]','$_POST[rainflex]') " ;
$result = mysql_query($order);  

//*Deze waarden kun je vrij veranderen
$brons = 44.00 ;
$zilver = 129.00 ;
$goud = 265.00 ;
$platinum = 599.00 ;

$greenfeebrons = 25.00 ;
$greenfeezilver = 17.50 ;
$greenfeegoud = 12.50 ;
greenfeeplatinum = 5.00 ;

$hcpx = 25.00 ;
$clubx = 65.00 ;
$academyx = 65.00 ;
$lockerx = 85.00 ;
$rainflexx = 45.00 ;

$allinx = 0.00 ;
$allinplatinumx = 0.00 ;

//*Deze waarden kun je niet veranderen

$nineholes = mysql_query('SELECT nineholes FROM calculator') ;
$eightteenholes = mysql_query('SELECT eightteenholes FROM calculator') ;
$hcp = mysql_query('SELECT hcp FROM calculator') ;
$club = mysql_query('SELECT club FROM calculator') ;
$academy = mysql_query('SELECT academy FROM calculator') ;
$locker = mysql_query('SELECT locker FROM calculator') ;
$rainflex = mysql_query('SELECT rainflex FROM calculator') ;
$allin = '0' ;
$allinplatinum = '0' ;


// Total
$bronstotaal =      $brons + (($nineholes / 4) * $greenfeebrons ) + (($eightteenholes / 5) * $greenfeebrons ) + (( $hcp / 6 ) * $hcpx ) +  (( $club / 7 ) * $clubx )  + (( $academy / 8 ) * $academyx) + (( $locker / 9 ) * $lockerx) + (( $rainflex / 10 ) * $rainflexx) + $allin + $allinplatinum;
$zilvertotaal =     $zilver + (($nineholes / 4)  * $greenfeezilver ) + (($eightteenholes / 5) * $greenfeezilver ) + (( $hcp / 6 ) * $hcpx ) +  (( $club / 7 ) * $clubx )  + (( $academy / 8 ) * $academyx) + (( $locker / 9 ) * $lockerx) + (( $rainflex / 10 ) * $rainflexx) + $allin + $allinplatinum;
$goudtotaal =       $goud + (($nineholes / 4)  * $greenfeegoud ) + (($eightteenholes / 5) * $greenfeegoud ) + (( $hcp / 6 ) * $hcpx ) +  (( $club / 7 ) * $clubx )  + (( $academy / 8 ) * $academyx) + (( $locker / 9 ) * $lockerx) + (( $rainflex / 10 ) * $rainflexx) + $allin + $allinplatinum;
$platinumtotaal =   $platinum + (($nineholes / 4)  * $greenfeeplatinum ) + (($eightteenholes / 5) * $greenfeeplatinum ) + (( $hcp / 6 ) * $hcpx ) +  (( $club / 7 ) * $clubx )  + (( $academy / 8 ) * $academyx) + (( $locker / 9 ) * $lockerx) + (( $rainflex / 10 ) * $rainflexx) + $allin + $allinplatinum;

if($result)
{
    echo ("<br> <u><b>Totaal:</b></u> <br>") ;
    echo ($bronstotaal) . "<br>" ;
    echo ($zilvertotaal) . "<br>" ;
    echo ($goudtotaal) . "<br>" ;
    echo ($platinumtotaal) . "<br>" ;
} 
else
{
    echo("<br>U heeft niet alles goed ingevuld");
}
  • 写回答

3条回答 默认 最新

  • duanlun4411 2013-12-05 09:05
    关注

    i recommended you to use mysqli btw:

    $result = mysql_query('SELECT * FROM calculator') ;
    
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    
    
    while ($row = mysql_fetch_assoc($result)) {
        $nineholes = $row['nineholes'];
        $eightteenholes = $row['eightteenholes'];
        $hcp =  $row['hcp'];
        $club = $row['club'];
        //.
        //.
        //.
        //and so on
    }
    

    so you only need one Select and not so many ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看