0

Hi can anyone tell me how I add a row to a database table (gamescores) that will record a userID and the number of points they have gained. I also have to update two session variables and use them to update values that appear on the screen by adding code to a function that i already have. Any help will be great

5
Contributors
9
Replies
11
Views
5 Years
Discussion Span
Last Post by Biiim
2

post your code. crystal ball gazing will not afford any useful answers. :(

Votes + Comments
I am afraid that it is a big plus for a programmer to understand specs by crystal ball gazing (I am too close to add it in my CV….) , but at least you must have some clues.
0

<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Prama: no-cache');
// the above headers will prevent the page output from being cached

include ("dbConnect.php");
$points=$_GET["points"];

'INSERT INTO gamescores (userID, visitScore)
VALUE ($formUser, $points)'

'UPDATE gamescores SET userID=$formUser, visitScore=$points'

// Part (1)
// add code here to...
// update the "gameScores" table with the new score
// and update the "scoreThisVisit" and "attemptsThisVisit" session variables
// return the "score this visit" and "attempts this visit" values seperated by the newline character

?>

0

So, this is the sum total of your code? Is this a school project?

There doesn't seem to be much in the way of effort here. Have a look at some php tutorials - mysql_query(), mysql_real_escape_string(), mysql_affected_rows()

0

No this is just one of the many files i have, there's quite alot of code so didn't want to post it all. Not looking for someone to tell me the answers was just wanting some to explain how i add a row to a database table and how to update the database. Just wanted to know if my code is the correct format. and was also looking for someone to explain how you update a session variable, i can't find anything on the internet.

0

explain how i add a row to a database table and how to update the database

Done - php.net manual and search for the terms mentioned in my last post. Also any search engine will give thousands of hits which tell how to do this.

Just wanted to know if my code is the correct format.

What code?, there is no code.

> i can't find anything on the internet.

Have you tried the php manual? Have you tried Google with 'update session variable php'?

I just tried it and got a shed full of relevant results.

Try again. :(

0

code i wanted to know if it was in the correct format, the code that i posted
'INSERT INTO gamescores (userID, visitScore)
VALUE ($formUser, $points)'

'UPDATE gamescores SET userID=$formUser, visitScore=$points'

Thank you, i will try again :)

0

if userid is numeric then ur query is fine, but if user id is text then u must enclose value with single quote.

$query="INSERT INTO gamescores (userID, visitScore) 
VALUE ('$formUser', $points)";

$query2="UPDATE gamescores SET userID='$formUser', visitScore=$points";

Edited by urtrivedi: n/a

0

No this is just one of the many files i have, there's quite alot of code so didn't want to post it all. Not looking for someone to tell me the answers was just wanting some to explain how i add a row to a database table and how to update the database. Just wanted to know if my code is the correct format. and was also looking for someone to explain how you update a session variable, i can't find anything on the internet.

Depends how you want to store the data in mysql.

you could have all players in the same table with their score eg.

player,score
1,2345
2,565
3,2255
4,3115
which you would do:

$query = "UPDATE gamescores SET Score = Score + $points WHERE player = $player";

or you could store it per visit, which is better as gives more data

visitid,playerid,score
1,1,845
2,1,1500
3,2,565
4,3,1100
5,4,800
6,3,1155
7,4,1000
8,4,1315

which would be:

$query = "INSERT INTO gamescores (`playerid`,`score`) VALUES($playerid,$score)";

I'd do the second as you can do so much more with it.

Also you can only put php variables in like that in double quotes, for single quotes you will have to concat them like this:

$query = 'INSERT INTO gamescores (`playerid`,`score`) VALUES('.$playerid.','.$score.')';

Edited by Biiim: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.