Stieny Posted December 21, 2009 Share Posted December 21, 2009 I have a page with a form. What I want the page to do is show the quantity submitted on the page as soon as it is posted. At this time when it is posted, it shows the values previous to posting the form info. I have tried meta and php no cache to no avail. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/ Share on other sites More sharing options...
Roq Posted December 21, 2009 Share Posted December 21, 2009 You're not being *TOO* clear, but it sounds like you just need to perform another query after you complete the form and post the data? Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981895 Share on other sites More sharing options...
Stieny Posted December 21, 2009 Author Share Posted December 21, 2009 Hmmmm. Let me try and be a little clearer. When the information is submitted from the form, there is information dependent on the submitted information that does not update. Essentially, I am trying to make a purchase. The purchase goes through, however the amount of money the user has does not reflect the purchase until you go to another page, or refresh the current page. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981899 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 If need be i can elaborate more, but i am just plain stuck. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981965 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Post some relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981966 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 Here is the posting code, which works... Â <?PHP if (isset($_POST['submit'])) { $fighters_buy=$_POST['fighters']; $rangers_buy=$_POST['rangers']; $clerics_buy=$_POST['clerics']; $mages_buy=$_POST['mages']; $rogues_buy=$_POST['rogues']; $assassins_buy=$_POST['assassins']; $monks_buy=$_POST['monks']; $engineers_buy=$_POST['engineers']; $siege_buy=$_POST['siege']; $cotg_buy=$_POST['cotg']; } if($fighters_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($rangers_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($clerics_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($mages_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($rogues_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($assassins_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($monks_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($engineers_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($siege_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } if($cotg_buy < 0) { print "Please enter a positive number."; echo $footer; exit(); } $gold_spent= ($fighters_buy * $config[fighters]) + ($rangers_buy * $config[rangers]) + ($clerics_buy * $config[clerics]) + ($mages_buy * $config[mages]) + ($rogues_buy * $config[rogues]) + ($assassins_buy * $config[assassins]) + ($monks_buy * $config[monks]) + ($engineers_buy * $config[engineers]) + ($siege_buy * $config[siege]) + ($cotg_buy * $config[cotg]); $total_buy = $fighters_buy+$rangers_buy+$clerics_buy+$mages_buy+rogues_buy+$assassins_buy+$monks_buy+$engineers_buy+$cotg_buy+ Â $user[fighters]+$user[rangers]+$user[clerics]+$user[rogues]+$user[assassins]+$user[monks]+$user[engineers]+$user[cotg]; $total_purchase = $fighters_buy+$rangers_buy+$clerics_buy+$mages_buy+rogues_buy+$assassins_buy+$monks_buy+$engineers_buy+$cotg_buy; if($total_buy > $total_hire) { print "You need more barracks to house that many troops."; echo $footer; exit(); } if($total_buy > $user[pop]) { print "You need more peasants to hire that many troops."; echo $footer; exit(); } if($gold_spent > $user['gold']) { print "You need $$gold_spent to hire that many troops."; echo $footer; exit(); } else { $new_gold=$user['gold']-$gold_spent; $new_pop=$user['pop']-$total_buy; $new_fighters=$user['fighters']+$fighters_buy; $new_rangers=$user['rangers']+$rangers_buy; $new_clerics=$user['clerics']+$clerics_buy; $new_mages=$user['mages']+$mages_buy; $new_rogues=$user['rogues']+$rogues_buy; $new_assassins=$user['assassins']+$assassins_buy; $new_monks=$user['monks']+$monks_buy; $new_engineers=$user['engineers']+$engineers_buy; $new_siege=$user['siege']+$siege_buy; $new_cotg=$user['cotg']+$cotg_buy; $new_pop=$user['pop']-$total_purchase; print "You purchased $total_purchase troops for $$gold_spent."; } //Update DB $query= "UPDATE members SET pop='".$new_pop."', fighters='".$new_fighters."', rangers='".$new_rangers."', clerics='".$new_clerics."', mages='".$new_mages."', rogues='".$new_rogues."', assassins='".$new_assassins."', monks='".$new_monks."', engineers='".$new_engineers."', siege='".$new_siege."', cotg='".$new_cotg."', gold='".$new_gold."' WHERE leader = '".($_SESSION['SESS_LEADER_NAME'])."'";Â $result = mysql_query($query); if($result) { } else { echo mysql_error(); } ?> Â code that is in a different table, but on the page and not reflecting changes made by the above code: Â Â <th>Resources</th> Â Â <td align="left">Â </td> Â </tr> Â <tr> Â Â <td><strong>Turns:</strong></td> <td align="left"><?PHP echo $user['turns'] ?></td> Â </tr> Â <tr> Â Â <td><strong>Gold:</strong></td> Â Â <td align="left">$<?PHP echo number_format($user['gold']) ?></td> Â </tr> Â <tr> Â Â <td><strong>Food:</strong></td> <td align="left"><?PHP echo number_format($user['food']) ?></td> Â </tr> Â <tr> Â Â <td><strong>Mana:</strong> </td> <td align="left"><?PHP echo number_format($user['mana']) ?></td> Â </tr> Â <tr> Â Â <td><strong>Land:</strong></td> Â Â <td align="left"><?PHP echo number_format($user['land']) ?></td> Â </tr> Â <tr> Â Â <td><strong>Peasants:</strong> </td> <td align="left"><?PHP echo number_format($user['pop']) ?></td> Â </tr> Â When posting, if you purchase anything, it will only be reflected by manually refreshing the page. ie change in gold, change in population, change in number of troops. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981976 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 to better understand visually: http://stieny72.x10hosting.com/game/ Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981983 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Here, where you have this bizarre little snippet...  if($result)    {    }   else    {      echo mysql_error();    }  You need to redirect back to this same page once your update is successful.  if ($result) {  header('Location: scriptname.php');  exit(); } else {  echo mysql_error(); }  On a side note. Simply echoing mysql_error() like that if there is a problem could pose a security risk. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981984 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 What should I do to rectify the side note security risk. I am teaching myself from scratch, so I am still relatively green. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981986 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 ahh, and the empty if. i had it redirect, however, upon redirect it would not echo the conformation that i had for completing the purchase. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981989 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 You should use trigger_error to trigger an error message. This can then be turned off (and logged) easily when your site goes into production. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981990 Share on other sites More sharing options...
PFMaBiSmAd Posted December 22, 2009 Share Posted December 22, 2009 Is your SELECT query inside some conditional logic so that is it not executed on the same page request that is due to the form submission? Â I would recommend the following headers to prevent caching of dynamically produced content (and make sure you sure you are not attempting to output headers after you have output content) - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981991 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 I have a page with a form. What I want the page to do is show the quantity submitted on the page as soon as it is posted. At this time when it is posted, it shows the values previous to posting the form info. I have tried meta and php no cache to no avail. Â I was referred here by a friend, who raved about how great these guys were, and especially patient with newbies. The condescending tone is not much appreciated by someone teaching themselves for less than a month. I am in the process of learning the language, and was assured I could use this as an aid to do so. Sorry if I offended you by my lack of experience in a help forum.... Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981994 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 I was referred here by a friend, who raved about how great these guys were, and especially patient with newbies. The condescending tone is not much appreciated by someone teaching themselves for less than a month. I am in the process of learning the language, and was assured I could use this as an aid to do so. Sorry if I offended you by my lack of experience in a help forum.... Â Where did that come from? Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-981995 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 Sorry. I am a little frustrated. I thought the signature: Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect. Â Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code. Â was directed at me personally... Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-982000 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Haha!!! Its just his sig. Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-982003 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 OK, if you forgive me for having my momentary lapse of goofiness,how can I post a conformation to the page I am redirected to?  if ($result) {  header('Location: barracks.php'); <- To this    This-> print "You purchased $total_purchase troops for $$gold_spent.";  exit(); } else { trigger_error(); } Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-982004 Share on other sites More sharing options...
Stieny Posted December 22, 2009 Author Share Posted December 22, 2009 Well, I figured out something that works for me. Thought I would post in the event it may solve someone else's problem  if ($result) { header('refresh: 4; url= barracks.php'); echo $success_header; print "You hired $total_purchase troops for $$gold_spent."; echo $footer;  exit(); } else {  trigger_error(); } Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-982688 Share on other sites More sharing options...
Roq Posted December 23, 2009 Share Posted December 23, 2009 edit: nevermind signature has been cleared up Quote Link to comment https://forums.phpfreaks.com/topic/185944-dynamic-data-not-updating/#findComment-982795 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.