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!
I am attempting to make a site where it is a website-game, and the gold after you log in won't show up...unless I run it to update through the login process, but it won't update the amount until they log in again. Therefore I need to add the script into the index page to auto update the gold as it increases and decreases. Here is my code:
also seifer.travisbsd.org/ if you want to check it out, only the login works, username/password: guest/guest. There should be 100 gold apearing on the bottom left corner...Under Username.
It looks like you get the gold value from the db everytime the page loads, and i don't see where you save the gold back to the db?
Presuming you want to get their gold value from the database when they login, but after that always use the session gold value then you probably want something like :
if(!isset($_SESSION['gold'])){
//connect to db and get gold value
$_SESSION['gold'] = $gold[0];
}
$final = $_SESSION['gold'];
...
I'm not sure how $final differs from $_SESSION['gold'] by looking at your code so you may not even need the $final = bit .. just stick with $_SESSION.
Then you just add values to $_SESSION['gold'] until at some point you'll want to write $_SESSION['gold'] back into the db.
No, because in the game I am creating the gold is going to have to be updated every time they visit a page, as they could find random amounts, kill things to give them gold, etc. I have seifer.travisbsd.org/test.php that adds gold to it, then go back to the main page and hit refresh..the added 500 gold doesn't show up.
It's hard to see exactly what's going on without seeing the code for the 3 relevant pages (main, test and freegold). The chunk of code above is the main page by the look of it, but that doesn't appear to save any gold values, so i presume test and freegold do that? Also, as you are reading/writing to the db on every page hit..where does the need for the session come into it?
Maybe create .phps files for those 3, might help clear my confusion
Well, without them the query evaluates to
SELECT uid FROM users WHERE uname = guest
and it will look for a column called guest in the db.
So normally you'de quote the var , like uname='guest' but as you want to use $_SESSION['username'] obviously '$_SESSION['username']' won't work as PHP will bork on the single quotes.
So to cut a long story short '{$_SESSION['username']}' evaluates to 'guest'
(the {}'s allow the internal 's to parse ok)
Oh okay, thanks a ton . Now my CSS isn't working for a couple of people, could you goto the my site and tell me what color the font is in the center of the main page..It is set to be #CCCCCC but he said it is black..
yup, it's black. But it's because of the quotes in your text/css bit..i.e change it to
<style type="text/css">
body{background-color:#626262;color:#CCCCCC;font-style:arial;font-size:10;}
td{color:#CCCCCC;font-style:arial;font-size:10;}
</style>