2008-12-04 59 views
0

我正在試圖製作一個計算器,它將從用戶那裏獲取輸入信息,並估計他們使用各種不同的VoIP服務會節省多少錢。基本的PHP窗體幫助

我已經設定,這樣的:

<form method="get" action="voip_calculator.php"> 
    How much is your monthly phone bill? 
    <input name="monthlybill" type="text" value="$" size="8"> 

    <p><input type="submit" name="Submit" value="Submit"> 
    </p> 
</form> 

在voipcalculator.php,我指向的頁面,我想打電話給「monthlybill」,但我無法弄清楚如何做到這一點。我也不知道如何使它對行中的數字進行減法。

這對你來說可能很簡單,但這對我來說是非常令人沮喪的,我虛心地尋求一些幫助。謝謝!

這裏是voip_calculator相關的東西,你也可以點擊網址,並提交了一些,看它(在)行動。我嘗試過各種次沒有成功調用它:

<table width="100%;" border="0" cellspacing="0" cellpadding="0"class="credit_table2" > 

<tr class="credit_table2_brd"> 
    <td class="credit_table2_brd_lbl" width="100px;">Services:</td> 
    <td class="credit_table2_brd_lbl" width="120px;">Our Ratings:</td> 
    <td class="credit_table2_brd_lbl" width="155px;">Your Annual Savings:</td> 
</tr> 

Your monthly bill was <?php echo 'monthlybill' ?> 

<?php echo "$monthlybill"; ?> 
<?php echo "monthlybill"; ?> 
<?php echo '$monthlybill'; ?> 
<?php echo 'monthlybill'; ?> 

<?php 
$monthybill="monthlybill"; 
$re=1; 
$offer ='offer'.$re.'name'; 
$offername= ${$offer}; 
while($offername!="") { 
    $offerlo ='offer'.$re.'logo'; 
    $offerlogo=${$offerlo}; 
    $offerli ='offer'.$re.'link'; 
    $offerlink=${$offerli}; 
    $offeran ='offer'.$re.'anchor'; 
    $offeranchor=${$offeran}; 
    $offerst ='offer'.$re.'star1'; 
    $offerstar=${$offerst}; 
    $offerbot='offer'.$re.'bottomline'; 
    $offerbottomline=${$offerbot}; 
    $offerca ='offer'.$re.'calcsavings'; 
    $offercalcsavings=${$offerca}; 

    echo '<tr > 
      <td > 
       <a href="'.$offerlink.'" target="blank"> 
        <img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" /> 
       </a> 
      </td> 
      <td > 
       <span class="rating_text">Rating:</span> 
       <span class="star_rating1"> 
        <img src="IMAGE'.$offerstar.'" alt="" /> 
       </span> 
       <br /> 
       <div style="margin-top:5px; color:#0000FF;"> 
        <a href="'.$offerlink.'" target="blank">Go to Site</a> 
        <span style="margin:0px 7px 0px 7px;">|</span> 
        <a href="'.$offeranchor.'">Review</a> 
       </div> 
      </td> 
      <td >'.$offercalcsavings.'</td> 
     </tr>'; 
    $re=$re+1; 
    $offer ='offer'.$re.'name'; 
    $offername= ${$offer}; 

} 
?> 

offercal(1,2,3,4,5,6,7)儲蓄調用一個名爲values.php他們在哪裏定義如下:

$offer1calcsavings="24.99"; 
$offer2calcsavings="20.00"; 
$offer3calcsavings="21.95"; 
$offer4calcsavings="23.95"; 
$offer5calcsavings="19.95"; 
$offer6calcsavings="23.97"; 
$offer7calcsavings="24.99"; 

回答

0

您需要從QueryString中獲取值並將其放入PHP變量中。

像這樣:

$monthlyBill = $_GET['monthlybill']; 

現在變量$ monthlyBill包含查詢字符串的值。

要顯示它:

echo "Your monthly bill is: $monthlyBill"; 
+0

我也試圖從另一個減去一個變量並顯示結果。我希望從$ offer1(2,3,4,5,6,7)calcalvings中扣除$ $每月帳單,然後顯示在該表中。應該問這是一個單獨的問題嗎? – 2008-12-04 01:19:02

+0

@pg:是的。一旦你完成,在這裏發佈鏈接。 – nickf 2008-12-04 01:33:17

+0

如果你正在吐輸入用戶,你真的應該或者調用htmlspecialchars()或者做某種驗證,否則你將會遇到XSS問題 – 2008-12-04 09:15:55

0

有一兩件事我是這樣

echo "<pre>"; 
print_r($_GET); 
echo "</pre>"; 

將這個地方在接收端,你會得到的發生了什麼的理解。

1

沒有足夠的細節提供答案,但讓我們簡化並假設您有一個數組中的'儲蓄'數字,比如companySavings。所以,你需要從用戶指定的值中減去這些值中的每一個?如果用戶點擊「提交」並重新加載頁面,則不需要打電話(如果您想要,可以這樣做)

將每月單據拉入var。

$monthlyBill = $_GET['monthlybill']; //you should do some checking to prevent attacks but that's another matter 

然後,當你正在構建節約名單會是這個樣子

<?php 
    //...code for the rest of the page and starting your table 

    foreach($companySavings as $savings){//insert each row into the table 
     echo("<tr><td>".(comapnyName/Image whatever..)."</td><td>$".$monthlyBill-$savings."</td></tr>); 
    } 
    //... end the table and rest of code 
    ?>