Skittalz Posted February 13, 2008 Share Posted February 13, 2008 I am creating a script that has the user input various values and then upon being submitted... The script does not refresh but displays the total. Can someone help me out? I've spent the last hour trying how to do it but I can't figure out what I'm doing wrong. Here's my code... Can someone help me out? <?php include 'quote_functions.php'; if(isset($_POST['Calculate'])) { if(numeric($_POST['width'])) { $price = $_POST['width']*$_POST['height']; if($_POST['bannertype'] == '1') { $price = $price * 3; } else if($_POST['bannertype'] == '2') { $price = $price * 2.5; } $price = number_format($price,2); } else { } } ?> <html><head></head><body><div align='center'> <form method="post" action="204.php"> <table align='center' width='600' bordercolor='#000000' bordercolor='#222222' bordercolorlight='#102444' border=1> <tr> <td background='cellbg.jpg' align='center'><font color='#171F2D'><b>-=| Online Quotation |=-</b></font></td></tr> <tr> <td> <table width=598 border=1> <tr> <td width=20%><div align='center'>Banner Type: <br> <select name="bannertype"> <option value="2">Simple Text Banner</option> <option value="1">Full Color Banner</option> </select></div> </td> <td width=20%><div align='center'>Height: <br> <select name="height"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> inch(es).</div> </td> <td width=20%><div align='center'>Width: <br> <input type="text" name="width" size="3" value="" /> inch(es).</div> </td> </tr> <tr> <td width=20%><div align='center'><b>Total</b>: $ <?php if(isset($price)) { echo $price; } else { echo "0.00"; }?> </div> </td> <td></td> <td> <input type="submit" name="Calculate" value="Calculate" /> <input type="submit" name="Order" value="Order" /> </td></tr></table> </table><br /> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 change if(isset($_POST['Calculate'])) { to if(!empty($_POST)){ Quote Link to comment Share on other sites More sharing options...
Skittalz Posted February 13, 2008 Author Share Posted February 13, 2008 change if(isset($_POST['Calculate'])) { to if(!empty($_POST)){ What did this do? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 13, 2008 Share Posted February 13, 2008 this is what it does. $val = ""; empty($val) would return true - so the statement is saying if its not empty. then if i go if(isset($val)), it checks to see if there is a variable called $val, therefore returning true. basically its changing to testing if the variabel is set - to if it is empty Quote Link to comment Share on other sites More sharing options...
Skittalz Posted February 13, 2008 Author Share Posted February 13, 2008 yeah... I understand that but it didn't really help me out. Was it supposed to do something in the big picture? What I am trying to do is to do the calculations and display the total without refreshing the page Quote Link to comment Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 In that case you need to use javascript, not php. PHP functions can only be executed by refreshing the page, as all php is done on the server. Javascript is done on the user's computer, so pages don't have to be refreshed. Quote Link to comment Share on other sites More sharing options...
Skittalz Posted February 13, 2008 Author Share Posted February 13, 2008 I heard something about a 204 No Content or something script? Is that possible to run? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 php can't operator without recalling the server. Meaning AJAX will need to call your server or refresh the page. However javascript can do simple math like this without needed to content the server. Quote Link to comment Share on other sites More sharing options...
Skittalz Posted February 13, 2008 Author Share Posted February 13, 2008 Alright... Thanks for the help! Now I know what to do ha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.