AltarofScience Posted September 24, 2011 Share Posted September 24, 2011 I have a code designed to build buildings on space colonies. The problem is that once you click the form button, the building is built, but you need to reload the page before it will show the updated count. Is there a way to refresh a page so that the change shows up without the user doing anything? <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT * FROM IMPrints"; $result=mysql_query($query); $name = mysql_result($result, 0, 'name'); $work = mysql_result($result, 0, 'workers'); $effi = mysql_result($result, 0, 'efficiency'); $cost = mysql_result($result, 0, 'cost'); $iron = mysql_result($result, 0, 'iron'); $copp = mysql_result($result, 0, 'copper'); $silv = mysql_result($result, 0, 'silver'); $titan = mysql_result($result, 0, 'titanium'); $gold = mysql_result($result, 0, 'gold'); $uran = mysql_result($result, 0, 'uranium'); $plat = mysql_result($result, 0, 'platinum'); $diam = mysql_result($result, 0, 'diamonds'); $oil = mysql_result($result, 0, 'oil'); $water = mysql_result($result, 0, 'water'); ?> <div class="building"> <p class="bd" id="name">| Name: <?php echo $name ?></p> <p class="bd" id="workers">| Staff: <?php echo $work ?></p> <p class="bd" id="efficiency">| Effic: <?php echo $effi ?></p> <p class="bd" id="cost">| Cost: <?php echo $cost ?></p> <p class="bd" id="iron">| Ir: <?php echo $iron ?></p> <p class="bd" id="copper">| Cop: <?php echo $copp ?></p> <p class="bd" id="silver">| Silv: <?php echo $silv ?></p> <p class="bd" id="titanium">| Titan: <?php echo $titan ?></p> <p class="bd" id="gold">| Gol:<?php echo $gold ?></p> <p class="bd" id="uranium">| Uran: <?php echo $uran ?></p> <p class="bd" id="platinum">| Plat: <?php echo $plat ?></p> <p class="bd" id="diamonds">| Diam: <?php echo $diam ?></p> <p class="bd" id="oil">| Oi: <?php echo $oil ?></p> <p class="bd" id="water">| Wat: <?php echo $water ?></p> <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $queryp = "SELECT Basic FROM IMBuilt WHERE idcol = $idcol"; $resultp = mysql_query($queryp); $Basic = mysql_result($resultp, 0); if(isset($_POST['built'])) { if($_POST) { $Badd = $Basic+$_POST['built']; $queryi="UPDATE IMBuilt SET Basic=$Badd WHERE idcol = $idcol"; mysql_query($queryi); } } ?> <p class="bd" id="built">| Built: <?php echo $Basic ?> |</p> <form class="bd" method="post" action="IronMineList.php"><input type="varchar" name="built"><input type="submit" value="Build"></form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/247791-_post-problems/ Share on other sites More sharing options...
gurpreet94 Posted September 24, 2011 Share Posted September 24, 2011 Couldn't you add this after your script executes the query? <meta http-equiv="refresh" content="0"> Quote Link to comment https://forums.phpfreaks.com/topic/247791-_post-problems/#findComment-1272443 Share on other sites More sharing options...
AltarofScience Posted September 24, 2011 Author Share Posted September 24, 2011 Couldn't you add this after your script executes the query? <meta http-equiv="refresh" content="0"> I guess I could if I had any idea what that did. Quote Link to comment https://forums.phpfreaks.com/topic/247791-_post-problems/#findComment-1272444 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2011 Share Posted September 24, 2011 You need to put the logic that displays the data AFTER the logic that updates the data. You also need to use just one set of code that makes a connection to the database server and mysql_result is the slowest way of accessing data from a query. You should just use one mysql_fetch_assoc statement to fetch the whole row at one time instead of a number of mysql_result statements. Quote Link to comment https://forums.phpfreaks.com/topic/247791-_post-problems/#findComment-1272445 Share on other sites More sharing options...
AltarofScience Posted September 24, 2011 Author Share Posted September 24, 2011 Okay, I got it: <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $queryp = "SELECT Basic FROM IMBuilt WHERE idcol = $idcol"; $resultp = mysql_query($queryp); $Base = mysql_result($resultp, 0); if(isset($_POST['built'])) { if($_POST) { $Badd = $Base+$_POST['built']; $queryi="UPDATE IMBuilt SET Basic=$Badd WHERE idcol = $idcol"; mysql_query($queryi); } } $queryf = "SELECT Basic FROM IMBuilt WHERE idcol = $idcol"; $resultf = mysql_query($queryf); $Basic = mysql_result($resultf, 0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/247791-_post-problems/#findComment-1272449 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.