Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make donation goal percent bar update on submit?
    primarykey
    data
    text
    <p>I have a script that displays a percentage bar and I plan on using it for our donation goals so users can see how much more money we need in a specific month. This is the code currently:</p> <pre><code>&lt;style&gt; .percentbar { background:#CCCCCC; border:1px solid #666666; height:25px; } .percentbar div { background: #28B8C0; height: 25px; border-right:1px solid black } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;?php include("config.php"); $data = mysql_query("SELECT * FROM donationgoal"); while ($info = mysql_fetch_array($data)) { if (isset($_POST['add'])) { $add = mysql_real_escape_string($_POST['add']); $total = $info['total'] + $add; } mysql_query("UPDATE donationgoal SET total = ".$total." "); $value = $info['total']; } echo $value; // Testing numbers. Replace with your own. $max = 100; $scale = 2.0; // Get Percentage out of 100 if ( !empty($max) ) { $percent = ($value * 100) / $max; } else { $percent = 0; } // Limit to 100 percent (if more than the max is allowed) if ( $percent &gt; 100 ) { $percent = 100; } ?&gt; &lt;form method="post"&gt; &lt;input type="text" name="add" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; &lt;div class="percentbar" style="width:&lt;?php echo round(100 * $scale); ?&gt;px;"&gt; &lt;div style="width:&lt;?php echo round($percent * $scale); ?&gt;px;"&gt;&lt;/div&gt; &lt;/div&gt; Percentage: &lt;?php echo $percent; ?&gt;% &lt;/body&gt; </code></pre> <p>Now this works completely fine (updates the table perfectly) however, after the page refreshes after the submit, the bar doesn't change. The only way it will change is if I manually refresh the page after I already submitted the form. Is there a way to make it so after the initial submit the bar will update?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload