Jump to content

Variable - Variable, isn't working?


3raser

Recommended Posts

<?php require ("style.css") ?>
<center>
<table cellpadding="0" cellspacing="0" id="sharedtable"> 
      <tr class="dblue"> 
        <th colspan="5"><strong>»  Message</strong></th> 
      </tr> 
  <tr class="one"> 

<td class="left">Want to know how much profit you made from your merching? This is the tool for you!</td>
      </tr> 
    </table> 
    <br /> 
   
<table cellpadding="0" cellspacing="0" id="sharedtable"> 
      <tr class="dblue"> 
        <th colspan="5"><strong>»  Calculator</strong></th> 
      </tr> 
  <tr class="one"> 

<td class="left"><form action='index.php' method='POST'>Starting item price <input type='text' name='3' /></td>
<td class="left">Ending price <input type='text' name='4' /></td>
<td class="left">Money you spent <input type='text' name='1' /></td>
<td class="left">Money you got back <input type='text' name='2' /></td>
<td class="left"><input type='submit' value='Calculate'></form></td>
      </tr> 
    </table> 
    <br />    

<?php

$sprice = $_POST['3'];
$eprice = $_POST['4'];
$one = $_POST['1'];
$two = $_POST['2'];

if ($sprice || $eprice || $one || $two) {

}
else

$bamm = $eprice - $sprice;
$total = $one - $two;

echo '<table cellpadding="0" cellspacing="0" id="sharedtable"> 
      <tr class="dblue"> 
        <th colspan="5"><strong>Calculation</strong></th> 
      </tr> 
  <tr class="one"> 

<td class="left">Money gained per item: '.$bamm .'</td>
<td class="left">Total money earned: '. $total .'</td>
      </tr> 
    </table> 
    <br />';  

?>

 

Why isn't $bamm showing up? $total shows up correctly, but the other doesn't. Here's the page: http://merchtool.webege.com/index.php

Link to comment
Share on other sites

Your site seems to be down, but to answer your question - if the second is working, and not the first, then the two variables for $bamm are not actually returning anything. Without the rest of the code, there's no way to be sure, but check that the first 2 variables actually have something.

Link to comment
Share on other sites

As said in the previous post. else needs brackets. Also, your logic is backwards. use ! to negate the if (!$sprice || !$eprice || !$one || !$two)

 

 

HTH

Teamatomic

 

Thanks to both of you. I can't believe I forgot the other two brackets!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.