Someone help me... I have problem with sending data to my mysql table

$conn = mysql_connect(“XXX”, “XXX”, “XXX”);

if ($_POST[‘score’]) {
$score = $_POST[‘score’];
print “status=Finished”;

$sql = “select * from XXX where user_name = ‘XXX’”;
$sql_res = mysql_query($sql,$conn) or die(mysql_error());
srand ((float) microtime() * 10000000);
while ($stats = mysql_fetch_array($sql_res)) {
$gold = $stats[‘cash’];


$gold = $gold + $score;

$q = “update usergame set cash = ‘$gold’ where user_name = ‘$HTTP_SESSION_VARS[user_name]’”;


$gold outputs as 0
$score which is the score from the flash game works!
cash is updated to the same as score… because $gold doesn’t register!
help i donno why this does htis

I think the problem is that when i try and select data … it doesnt work because i tried to select something else and it didn’t work…
ugh… this is driving me nuts

This doesn’t belong in Flash ActionScript so I moved it over.

When $_POST[‘score’] isn’t set, is the script still supposed to run?

If you’re just trying to add score to the gold, you can always go

“UPDATE mytable SET cash = cash + score WHERE… etc”

hope this helps

$q = “update usergame set cash = cash + $score where user_name = ‘$HTTP_SESSION_VARS[user_name]’”;

i used that and it still doesn’t add cash to score to get cash…
it just inserts score

if have if (!$_POST[‘score’]) {
do this
} else {
$score = $_POST[‘score’];


i donno why cash doesn’t register… score should be the one that doesn’t

i put if (!$gold) {

before to see if gold even got selected and it didnt

  $result = mysql_query($q) or die(mysql_error()); 
  #this is for debuggin of queries which should really
  #add to all queries when still
  echo $result;

Its updating fine the process is that cash isn’t getting selected and gold isn’t getting defined

 #try this.
  $sql = "select * from XXX where user_name = 'XXX'";
 $sql_res = mysql_query($sql,$conn) or die(mysql_error());
 srand ((float) microtime() * 10000000);
 while ($stats = mysql_fetch_array($sql_res)) {
  $gold = stats['cash'] + $score;
 echo $gold; #to check if its all oke.
 $q = "update usergame set cash ='".$gold."' where user_name ='".$HTTP_SESSION_VARS[user_name]."'";
 $result = mysql_query($q) or die(mysql_error()); 
 echo $result; #debug whats output..

i found the error Resource id #2
when itry and select cash
i donno what the means or how to fix it

$gold = 406 $result = status=1
$gold shouldn’t of been 406 becuase 406 is what i scored…
it should of added 100 to 406
because 100 was my initial gold but i tdidnt select it right

oh i gues that status = 1 should just be 1 so yea it updated fine

As you can see now, echoing back youre variables for debug is a very good thing to do :slight_smile: it will solve alot of youre problems while coding the pages. the mysql_error is the same thing. And if the query really doesnt work try it directly from the prompt command or in any other query window. that to will make you see youre errors very fast.

lol yea it does help but my problem still remains! i can’t get cash selected

Resource id #2 thats the error message i get when i try and select stufff

Well as i said execute that query in a prompt window or use that t00l thats what i use, it helps me with a lot of things… or just phpmyadmin… make the query in the query window and see if you get results. and again echo back all vars that you needs to see where it went wrong!

Resource id #2 do u kno what that means though?

#this into 
$sql_res = mysql_query($sql,$conn) or die(mysql_error());
$sql_res = mysql_query($sql) or die(mysql_error());

It means something wrong with the query :slight_smile: Thats why you should try them out in a query window instead from php pages. it really helps!

Resource id #2
i still get it lol

the thing updates fine it just doesn’t select cash