Hi,
Got another small problem here.
This code tests if a user is valid when he or she fills in the predictions.
And if valid, inserts it into the database.
<?
if (isset($POST['aktie']) && $POST['aktie'] == "controleren")
{
$query_voorspellencontrole="
SELECT *
FROM Gebruikers
WHERE Username='".$POST['Username']."'
AND Pass='".$POST['Pass']."'";
if (!$result_voorspellencontrole=mysql_query($query_voorspellencontrole))
{
echo "error";
}
elseif (mysql_num_rows($result_voorspellencontrole) == 0)
{
echo "error";
}
elseif (is_numeric($_POST['WedstrijdID']))
{
$UserID = mysql_result($result_voorspellencontrole, 0, "UserID");
$ScoreThuis = (is_numeric($_POST['ScoreThuis'])) ? $_POST ['ScoreThuis'] : 0;
$ScoreUit = (is_numeric($_POST['ScoreUit'])) ? $_POST ['ScoreUit'] : 0;
$query_voorspellingtoevoegen="
INSERT INTO Voorspellingen (UserID, WedstrijdID, ScoreThuis, ScoreUit)
VALUES (".$UserID.", ".$_POST['WedstrijdID'].", ".$_POST['ScoreThuis'].", ".$_POST['ScoreUit'].")";
if (!mysql_query($query_voorspellingtoevoegen))
{
echo "Fout in de query:<br>\n".$query_voorspellingtoevoegen."<br>\n".mysql_error();
}
else
{
echo "<center><b>Bedankt voor uw voorspelling!";
}
}
else
{
echo "Er is geen (geldig) WedstrijdID bekend";
}
}
?>
The code below is used by the users for filling in the predictions:
<?
$query_voorspellen="SELECT * FROM Wedstrijden, Gebruikers WHERE Wedstrijden.WedstrijdStatus='open'";
if (!$result_voorspellen=mysql_query($query_voorspellen))
{
echo "Fout in de query:<br>\n".$query_voorspellen."<br>\n".mysql_error();
}
else
{
echo "<div align='center'>";
echo "<form action=".$_SERVER['PHP_SELF']." method=\"post\">";
echo "<input type='hidden' name='aktie' value='controleren'>";
echo "<table border='0' width='550' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='100'>Datum</td>";
echo "<td width='145' align='left'>Team 1</td>";
echo "<td width='10'> - </td>";
echo "<td width='145' align='right'>Team 2 </td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'><hr></td>";
echo "<td width='145' align='left'><hr></td>";
echo "<td width='10'><hr></td>";
echo "<td width='145' align='right'><hr></td>";
echo "<td width='150' align='right'><hr></td>";
echo "</tr>";
$i=1;
while($row_voorspellen=mysql_fetch_array($result_voorspellen))
{
$sTeamThuis = 'foutje';
if ( ($resTeam = mysql_query('SELECT TeamNaam FROM Teams WHERE TeamID='.$row_voorspellen['TeamThuis'] )) !== false )
{
if ( $asTeam = mysql_fetch_assoc($resTeam) )
{
$sTeamThuis = $asTeam['TeamNaam'];
}
}
$sTeamUit = 'foutje';
if ( ($resTeam = mysql_query('SELECT TeamNaam FROM Teams WHERE TeamID='.$row_voorspellen['TeamUit'] )) !== false )
{
if ( $asTeam = mysql_fetch_assoc($resTeam) )
{
$sTeamUit = $asTeam['TeamNaam'];
}
}
echo "<input type='hidden' name='WedstrijdID' value='$row_voorspellen[WedstrijdID]'>";
echo "<tr>";
echo "<td width='100'>$row_voorspellen[Dag]</td>";
echo "<td width='145' align='left'>$sTeamThuis</td><td><input type='text' name='ScoreThuis' maxlength='2' size='3'></td>";
echo "<td width='10' align='center'> - </td>";
echo "<td width='145' align='right'>$sTeamUit</td><td><input type='text' name='ScoreUit' maxlength='2' size='3'>";
echo "</tr>";
$i++;
}
echo "<tr>";
echo "<td width='100'><hr></td>";
echo "<td width='145' align='left'><hr></td>";
echo "<td width='10'><hr></td>";
echo "<td width='145' align='right'><hr></td>";
echo "<td width='150' align='right'><hr></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>Gebruikersnaam: <input type='text' name='Username'></td>";
echo "<td colspan='3' align='right'>Wachtwoord: <input type='password' name='Pass'></td>";
echo "</tr>";
echo "</table>";
echo "<br><br><input type='submit' value='Voorspel'>";
echo "</form>";
}
?>
My problem is that it only inserts the predictions of the last match and not all of them!
What am i doing wrong?