I am not-so-gently pulling my hair out over here.
I created a simple MySQL update using PHP that changes a flag in the db from '1' to '2' if it was previously set to '1', or from a '2' to '1' if it was previously set to '2'. Nothing special there.
However, when I click the link, the db is updating accordingly but the text on the site is doing something very funky. I have attached a video to show what I mean: http://gfycat.com/RipeCarefulChinesecrocodilelizard
At the beginning of the video, you will see what's happening as I click quickly. Closer to the middle of the video, I click a link and then refresh the page. Refreshing shows the correct flagging for each of the items.
I have never experienced this before. I am not sure if there is some weird caching issue happening or what. That said, this is super simple HTML/PHP markup grabbing variables using GET and shouldn't be screwing up like this.
Any ideas what might be going on? (Better yet, what a fix could be?)
The code is as follows:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("selected_db") or die(mysql_error());
// if the vendor's commission is being changed
$vendor_id = $_GET['id'];
$switch_type = $_GET['type'];
if ($switch_type == "reg") {
$result2 = mysql_query("UPDATE vendors SET vendor_commission_rate='1' WHERE vendor_id='$vendor_id'")
or die(mysql_error());
}
elseif ($switch_type == "pro") {
$result2 = mysql_query("UPDATE vendors SET vendor_commission_rate='2' WHERE vendor_id='$vendor_id'")
or die(mysql_error());
}
?>
<style>
table, tr, td, th {
padding:5px;
}
</style>
<center>
<table>
<tr>
<td colspan="5" style="padding-bottom:20px; text-align:center; font-size:130%">Item sold for <strong>$20.00</strong></td></tr>
<th valign="bottom">Vendor</th><th align="center" valign="bottom">Commission<br />Rate</th><th align="center" valign="bottom">Vendor<br />Commission</th><th align="center" valign="bottom">supplier<br />Commission</th><th></th></tr>
<?php
$result = mysql_query("SELECT * FROM vendors")
or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$vendor_id = $row['vendor_id'];
$vendor_name = $row['vendor_name'];
$rate_amount = $row['vendor_commission_rate'];
if ($rate_amount == 1) {
$rate_amount = 0.5;
$rate_name = "<a href=\"?id=".$row['vendor_id']."&type=pro\">Upgrade to Pro</a>";
}
if ($rate_amount == 2) {
$rate_amount = 0.75;
$rate_name = "<a href=\"?id=".$row['vendor_id']."&type=reg\">Switch to Reg</a>";
}
$vendor_commission = 20 * $rate_amount;
$supplier_commission = 20 - $vendor_commission;
$rate_amount_output = $rate_amount * 100;
echo "<tr><td>".$vendor_name."</td><td align=\"center\">".$rate_amount_output."%</td><td align=\"center\">$".number_format($vendor_commission,2)."</td><td align=\"center\">$".number_format($supplier_commission,2)."</td><td>".$rate_name."</td></tr>";
}
?>
</table>
</center>
Thanks for your help!