Forum Moderators: coopster
// HTML
echo"<FORM method='post' action='update-topscoorder-db.php'>";
echo "<TABLE width='100%' bordercolor='#000000' style='border-collapse:collapse' border='1'>";
echo "<TR>";
echo "<TD class='hoofd' colspan='4'>Topscoorder</TD>";
echo "</TR>";
include("dbconnect.php");
$result = mysql_query("SELECT `naam`,`goals`, `id` FROM topscoorder ORDER BY `goals` DESC");
while($row = mysql_fetch_assoc($result))
{
echo "<TR>";
echo "<TD class='menu'><INPUT type='checkbox' name='id[]' value='".$row['id']."'></TD>";
echo "<TD class='menu'>".$row['naam']."</TD>";
echo "<TD class='menu'>".$row['goals']."</TD>";
echo "<TD class='menu'><INPUT type='text' name='score'></TD>";
}
//rest of code
================================================
<?php
error_reporting(E_ALL);
include("dbconnect.php");
include("dbconnect.php");
$result = mysql_query("SELECT `id` FROM topscoorder);
$check = $_POST['id'];
$score = $_POST['score'];
while($row = mysql_fetch_assoc($result))
{
while(".$row['id']." == $check)
{
$query = "UPDATE `topscoorder` SET goals=goals+$score";
$result = mysql_query($query) or die ('Fout: '.mysql_error());
if (mysql_affected_rows()==1)
{
echo "<p>UPDATE voltooid. <a href='view-topscoorder.php'>Klik hier om terug te gaan</a></p>";
}
else
{
echo "<p>UPDATE afgebroken!</p>";
}
}
}
?>
<?php
error_reporting(E_ALL);
include("dbconnect.php");
$check = $_POST['id'];
$score = $_POST['score'];
$getGoals=mysql_query("SELECT goals FROM toscoorder WHERE id='$check'") or die ('Fout: '.mysql_error());
while($row=mysql_fetch_assoc($getGoals))
{
$newGoals=$row["goals"]+$score;
$query = "UPDATE topscoorder SET goals='$newGoals' WHERE id='$check'";
$result = mysql_query($query) or die ('Fout: '.mysql_error());
if (mysql_affected_rows($result)<1)
{
echo "<p>UPDATE afgebroken!</p>";
}
else
{
echo "<p>UPDATE voltooid. <a href='view-topscoorder.php'>Klik hier om terug te gaan</a></p>";
}
}
?>
Also, from the PHP manual:
Note: When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.