简体   繁体   中英

basic php form help

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

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.

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 eg

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM