Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>that's because your <code>insert</code> query is after your <code>select</code> query, you have to insert the new record before getting the data from <code>mysql</code> your code would be like this:</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"); if (isset($_POST['add'])) { $add = mysql_real_escape_string($_POST['add']); mysql_query("UPDATE donationgoal SET `total` = `total` + ".$add." "); } $data = mysql_query("SELECT * FROM donationgoal"); while ($info = mysql_fetch_array($data)) { $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><strong>BTW:</strong> Please Please Please stop using mysql and use <code>mysqli</code> instead.</p>
    singulars
    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