[英]basic php form help
我正在嘗試制作一個可以接收用戶輸入的計算器,並為他們估計如果他們使用各種不同的VoIP服務,他們將節省多少錢。
我已經這樣設置:
<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的相關內容,您也可以單擊url並提交一個數字以在操作中查看它。 我多次嘗試調用它都沒有成功:
<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";
我要做的一件事就是這個
echo "<pre>";
print_r($_GET);
echo "</pre>";
將其放在接收端的某個地方,您將了解發生了什么。
沒有提供足夠的詳細信息來提供答案,但是讓我們簡化一下,並假設您擁有陣列中的“節省”數字,例如companySavings。 因此,您需要從用戶指定的值中減去其中的每一個? 您不需要打電話(如果需要,您可以...)
當用戶單擊“提交”並再次加載頁面時,將月費單放入變量中
$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
?>
您需要從QueryString中獲取值並將其放入PHP變量中。
像這樣:
$monthlyBill = $_GET['monthlybill'];
現在,變量$ monthlyBill包含QueryString中的值。
要顯示它:
echo "Your monthly bill is: $monthlyBill";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.