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 /> Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/ 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)){ Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-465556 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? Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-465565 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 Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-465610 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 Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-466060 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. Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-466068 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? Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-466073 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. Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-466079 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 Link to comment https://forums.phpfreaks.com/topic/90835-no-refresh-help/#findComment-466082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.