基本 php 表单帮助

发布于 2024-07-09 04:23:53 字数 3106 浏览 4 评论 0原文

我正在尝试制作一个计算器,该计算器将接受用户的输入并为他们估计如果他们使用各种不同的 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 并提交一个数字以在(in)操作中查看它。 我多次尝试调用它但没有成功:

<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) savings 调用一个名为 value.php 的文件,它们的定义如下:

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

I'm trying to make a calculator that will take inputs from users and estimate for them how much money they'll save if they use various different VoIP services.

I've set it up like this:

<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>

On voipcalculator.php, the page I point to, I want to call "monthlybill" but I can't figure out how to do it. I also can't figure out how to make it do the subtraction on the numbers in the rows.

This may be very simple to you but it's very frustrating to me and I am humbly asking for a bit of help. Thank you!

Here is the relevant stuff from voip_calculator, you can also click on the url and submit a number to see it in (in)action. I tried various times to call it with no success:

<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)savings calls to a file called values.php where they are defined like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

网名女生简单气质 2024-07-16 04:23:53

我做的一件事就是

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

把它放在你的接收端的某个地方,你就会明白发生了什么。

One thing i do is this

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

Put this somewhere in your receiving end and you'll get an understanding of whats happening.

如梦亦如幻 2024-07-16 04:23:53

没有提供足够的详细信息来提供答案,但让我们简化并假设您在数组中拥有“储蓄”数字,例如 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
   ?>

Not enough detail provided for an answer but let's simplify and assume you have the 'savings' numbers in an array, say, companySavings . So, you need to subtract each of these from the value the user specifies right? You don't need to call something (you could if you want...)

when the user clicks 'Submit' and the page is loaded again pull the monthlybill into a var e.g.

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

Then, when you are building the list of savings it would look something like this

    <?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
   ?>
梦断已成空 2024-07-16 04:23:53

您需要从 QueryString 获取值并将其放入 PHP 变量中。

像这样:

$monthlyBill = $_GET['monthlybill'];

现在变量 $monthlyBill 包含来自 QueryString 的值。

要显示它:

echo "Your monthly bill is: $monthlyBill";

You need to get the value from the QueryString and put it into a PHP variable.

Like this:

$monthlyBill = $_GET['monthlybill'];

Now the variable $monthlyBill contains the value from the QueryString.

To display it:

echo "Your monthly bill is: $monthlyBill";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文