Basic php help

I am trying to make a calculator that will input data from users and estimate for them how much money they will save if they use various different VoIP services.

I installed it 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, on the page I point to, I want to call it "monthly", but I can't figure out how. I also cannot figure out how to do this by subtracting numbers in strings.

It may be very easy for you, but it makes me very upset and I humbly ask for a little help. Thank!

Here is the relevant stuff from voip_calculator, you can also click on the url and submit the number to see it in (in) action. I've tried different times to call this without 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 named values.php where they are defined as follows:

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

      

0


source to share


3 answers


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

Like this:

$monthlyBill = $_GET['monthlybill'];

      



The $ monthBill variable now contains the value from the QueryString.

To display it:

echo "Your monthly bill is: $monthlyBill";

      

0


source


Not enough detail to answer, but oversimplify and assume that you have savings numbers in an array, say companySavings. So, you have to subtract each one from the value the user specifies correctly? You don't need to call something (you can if you want ...)

when the user clicks submit and the page loads again pull the monthly invoice to var for example.

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

      



Then, when you build your savings list, it will 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
   ?>

      

+1


source


One thing I do is

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

      

Place this somewhere at your end of the reception and you can see what's going on.

0


source







All Articles