test return value from db_query before assuming it is valid

make the sql query form consistent in usage by cleaning up instances
where db_query's result was not inspected before attempting to fetch row
data from the handle

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
elij 2011-05-11 16:17:12 -07:00 committed by Lukas Fleischer
parent d38f3460e5
commit 0898f1447a
7 changed files with 135 additions and 68 deletions

View file

@ -8,39 +8,45 @@
#
$q = "SELECT * FROM PackageVotes WHERE UsersID = ". $uid;
$q.= " AND PackageID = ".$row["ID"];
if (!mysql_num_rows(db_query($q, $dbh))) {
echo " <input type='submit' class='button' name='do_Vote'";
echo " value='".__("Vote")."' /> ";
} else {
echo "<input type='submit' class='button' name='do_UnVote'";
echo " value='".__("UnVote")."' /> ";
$result = db_query($q, $dbh);
if ($result) {
if (!mysql_num_rows($result)) {
echo " <input type='submit' class='button' name='do_Vote'";
echo " value='".__("Vote")."' /> ";
} else {
echo "<input type='submit' class='button' name='do_UnVote'";
echo " value='".__("UnVote")."' /> ";
}
}
# Comment Notify Button
#
$q = "SELECT * FROM CommentNotify WHERE UserID = ". $uid;
$q.= " AND PkgID = ".$row["ID"];
if (!mysql_num_rows(db_query($q, $dbh))) {
echo "<input type='submit' class='button' name='do_Notify'";
echo " value='".__("Notify")."' title='".__("New Comment Notification")."' /> ";
} else {
echo "<input type='submit' class='button' name='do_UnNotify'";
echo " value='".__("UnNotify")."' title='".__("No New Comment Notification")."' /> ";
$result = db_query($q, $dbh);
if ($result) {
if (!mysql_num_rows($result)) {
echo "<input type='submit' class='button' name='do_Notify'";
echo " value='".__("Notify")."' title='".__("New Comment Notification")."' /> ";
} else {
echo "<input type='submit' class='button' name='do_UnNotify'";
echo " value='".__("UnNotify")."' title='".__("No New Comment Notification")."' /> ";
}
}
if ($row["OutOfDateTS"] === NULL) {
echo "<input type='submit' class='button' name='do_Flag'";
echo " value='".__("Flag Out-of-date")."' />\n";
} else {
echo "<input type='submit' class='button' name='do_UnFlag'";
echo " value='".__("UnFlag Out-of-date")."' />\n";
if ($row["OutOfDateTS"] === NULL) {
echo "<input type='submit' class='button' name='do_Flag'";
echo " value='".__("Flag Out-of-date")."' />\n";
} else {
echo "<input type='submit' class='button' name='do_UnFlag'";
echo " value='".__("UnFlag Out-of-date")."' />\n";
}
if ($row["MaintainerUID"] === NULL) {
echo "<input type='submit' class='button' name='do_Adopt'";
echo " value='".__("Adopt Packages")."' />\n";
} else if ($uid == $row["MaintainerUID"] ||
$atype == "Trusted User" || $atype == "Developer") {
if ($row["MaintainerUID"] === NULL) {
echo "<input type='submit' class='button' name='do_Adopt'";
echo " value='".__("Adopt Packages")."' />\n";
} else if ($uid == $row["MaintainerUID"] ||
$atype == "Trusted User" || $atype == "Developer") {
echo "<input type='submit' class='button' name='do_Disown'";
echo " value='".__("Disown Packages")."' />\n";
}