Refresh to notice difference?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Birdum
Forum Newbie
Posts: 2
Joined: Sat Jun 19, 2010 2:21 pm

Refresh to notice difference?

Post by Birdum »

Hello guys,

Below i have supplied test code that I have been playing with to try and figure out why its not working on my official page. Of course its much more simplified but you get the idea.

Description/Run Through: So basically I have it accessing a row in my database, and then getting a variable in the "cash" column. I have a button that if pressed, it takes my cash and subtracts one from it. "Button Pressed" Was added to make sure the button was being pressed, which is was. Then it updates the new cash level back into the database. On the page it displays the button and the variable for total cash.

Problem: When I press the button it, gets the new variable and puts it in the database. But it doesn't change visually until I refresh the page.

Link: http://terminaldirective.site90.net/test.php

Code:

Code: Select all

<?php
mysql_connect("-", "-", "-") or die(mysql_error());
mysql_select_db("-") or die(mysql_error());

$data = mysql_query("SELECT * FROM mem_resources  WHERE username = 'Birdum'") or die(mysql_error());
while ($row = mysql_fetch_assoc($data))
{
$totalcash = $row['cash'];
}

if ($_POST['buy'])
{
echo "Button pushed";
$totalcash = $totalcash - 1;
mysql_query("UPDATE mem_resources SET cash = '$totalcash' WHERE username = 'Birdum'") or die(mysql_error);
}

echo "<form method='POST'>";
echo "<input type='submit' name='buy' value='Buy Mines'>";
echo "</form>";
echo "Current Cash: $totalcash";

?>
Thanks in Advance!

Birdum
Last edited by Birdum on Sat Jun 19, 2010 9:17 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Refresh to notice difference?

Post by requinix »

You'll have to provide more accurate code. For one, your query uses a variable that your code doesn't have.
Birdum
Forum Newbie
Posts: 2
Joined: Sat Jun 19, 2010 2:21 pm

Re: Refresh to notice difference?

Post by Birdum »

Yeah after I played around with it a bit I caught that variable it was a variable I had previously updated.
But it didnt solve the issue at hand. I've been searching and read something about Cache could this possibly be it? Also what do you mean I'll have to provide more accurate code?
Post Reply