I want a loop, that echoes some football matches and my users bets on them, and then the possibillity to change the bets. I have two tables in my db:
vm_kampe
which is the matches where res
is the result:
|id |hhold |uhold |res |
|1 |Rusland |Saudi |NULL |
|2 |Egypten |Uruguay |NULL |
... and so on
and vm_kampe
, which is the users bets:
|id |resu |
|1 |2-1 |
|2 |1-3 |
... and so on.
My update site is like this:
SELECT * FROM vm_kampe k JOIN vm_207 u ON k.id = u.id
...
foreach($results as $row){
echo '<div class="vm_kupon_row">
<div class="vm_id"><input type="hidden" name="kampids[]" value="'.$row->id.'"></div>
<div class="vm_kampe">'.$row->hhold.' - '.$row->uhold.'</div>
<div class="vm_result"><input class="vm_resultat" type="text" name="resultats['.$row->id.']" placeholder="X-X" value="'.$row->resu.'"></div>
<input type="submit" class="godkend-vm-kupon" name="submit['.$row->id.']" value="Godkend">
My POST site is like this:
$res = $mysqli->real_escape_string($_POST['resultats']);
$id = $mysqli->real_escape_string($_POST['kampids']);
FOREACH ($_POST as $p) {
$gid = $p['id'];
$result = $p['res'];
$sql = "UPDATE vm_207 SET resu = '$result' WHERE id = '$gid'";
};
But if I try editting a bet and press submit, the bet will just stay the same as before. All I want is for me to be able to update every match. Please help :)
UPDATE I just tried this in the post code:
$id = $_POST['kampids'];
$res = $_POST['resultats'];
foreach ( $id as $key => $k) {
print "The match is " .$k. " and the result is " .$res[$key];
};
I tried writing 2-1 in the first game and the print was:
The match is 1 and the result is 2-1 The match is...
So as I can see, the function works, so now I just need it to update the table..