[英]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.