0

Hi i got this array here and i want to put it into mysql database, here is my array

$v = "Tom: 2000, Bob: 300, Jack: 500"

$x is Array ( [0] => Array ( [0] => Tom [1] => 2000 ) [1] => Array ( [0] => Bob [1] => 300 ) [2] => Array ( [0] => Jack [1] => 500 ) )

and this is my code to put it into database:

$f=explode(",",$v);

for($i=0;$i<sizeof($f);$i++){
$x[$i]=explode(": ",$f[$i]);

$player=$x[$i][0];
$win=$x[$i][1];
$sql         = "UPDATE scores SET win=$win WHERE player='$player'";
$result      = $conn->query( $sql );
}

but the problem is for loop only puts 'Tom' and '2000' (which are first) into database and nothing happens to other player's row, i think this code should work fine but i cant find what is the problem.

1 Answer 1

1

Do the other records exist? I see you're doing an UPDATE and not an INSERT, so maybe the other records mismatch on "player"?

You also might want to use trim() on $player and $win, to remove any whitespace from the explode() output.

Sign up to request clarification or add additional context in comments.

1 Comment

all other records exist and they match the player, i will try trim().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.