3raser Posted January 4, 2010 Share Posted January 4, 2010 <?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 https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/ Share on other sites More sharing options...
Hybride Posted January 4, 2010 Share Posted January 4, 2010 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 https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/#findComment-987950 Share on other sites More sharing options...
oni-kun Posted January 4, 2010 Share Posted January 4, 2010 var_dump($eprice,$sprice); What does this return? Put it in place of your '$bamm = ...' Link to comment https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/#findComment-987953 Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2010 Share Posted January 4, 2010 Your if(){}else logic is incorrect. Your if(){} statement is empty and because you are not using {} around the code in the else part of that, only the first line after the else is part of the else statement. Link to comment https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/#findComment-987954 Share on other sites More sharing options...
teamatomic Posted January 4, 2010 Share Posted January 4, 2010 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 Link to comment https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/#findComment-987967 Share on other sites More sharing options...
3raser Posted January 4, 2010 Author Share Posted January 4, 2010 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 https://forums.phpfreaks.com/topic/187083-variable-variable-isnt-working/#findComment-987994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.