Ive posted this code before, but I couldn't find the solution and no one else posted it. So if anyone has any clue as to why its not working correctly. What I mean by not working correctly is. You click Edit and it edits the top entry.
<?
require "config.php";
$table = "Ranks";
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname) or die(mysql_error());
$Rank = $_POST['Rank'];
$INFO = $_POST['INFO'];
$Rnum = $_POST['Rnum'];
echo "<form name=\"RanksEdit\" method=\"post\" action=$PHP_SELF>";
if ($Submit == "Add")
{
if ($ahead == "+")
{
$Add = "INSERT INTO $table VALUES('','$Rank','$INFO','$Rnum')";
mysql_query($Add) or die(mysql_error());
}
else
{
$Add = "INSERT INTO $table VALUES('','$Rank','$INFO','$Rnum')";
mysql_query($Add) or die(mysql_error());
}
$action = "";
}
elseif ($Submit == "Modify")
{
$idedit = $_REQUEST['id'];
$Update = "UPDATE $table SET Rank='$Rank', INFO=trim('$INFO'), Rnum='$Rnum' WHERE id='$idedit'";
mysql_query($Update) or die(mysql_error());
$action = "";
}
// Delete News
if ($action=="delete")
{
$Delete = "DELETE FROM $table WHERE id='$id'";
mysql_query($Delete) or die(mysql_error());
}
if ($id != "")
{
// Show selected news
$Show = mysql_db_query($dbname, "SELECT * FROM $table WHERE id='$id'");
$ShowRow = mysql_fetch_array($Show);
$ShowRank = strip_tags($ShowRow["Rank"]);
$ShowINFO = strip_tags($ShowRow["INFO"]);
$ShowRnum = strip_tags($ShowRow["Rnum"]);
mysql_free_result($Show);
}
// Show all news
$result = mysql_db_query($dbname, "SELECT * FROM $table ORDER BY ID");
$row = mysql_fetch_array($result);
if ($action=="edit")
{
echo "Rank Title : <br><input type=\"text\" name=\"Rank\" value=$ShowRank size=\"20\">";
}
else
{
echo "Rank Title : <br><input type=\"text\" name=\"Rank\" size=\"20\">";
}
echo "<br>";
echo "Rank Description : <br>";
echo "<textarea name=\"INFO\" cols=\"60\" rows=\"15\" wrap=\"VIRTUAL\">";
if ($action=="edit")
{
print trim($ShowINFO);
}
print "</textarea>";
echo "<br>";
if ($action=="edit")
{
echo "Rank Level : <br><input type=\"text\" name=\"Rnum\" value=$ShowRnum size=\"20\">";
}
else
{
echo "Rank Level : <br><input type=\"text\" name=\"Rnum\" size=\"20\">";
}
echo "<br>";
if ($action!="edit")
{
print "<input type=\"submit\" name=\"Submit\" value=\"Add\">";
}
else
{
echo "<input type=\"hidden\" name=\"id\" value=".$row["id"]." size=\"20\">";
print "<input type=\"submit\" name=\"Submit\" value=\"Modify\">";
}
echo "<input type=\"button\" value=\"Reset\" onClick=\"location.href = 'http://vampclan.com/RankAdmin.php'\">";
echo "</form>";
while ($id=$row["id"])
{
$id = $row["id"];
$Rank = $row["Rank"];
$INFO = $row["INFO"];
$Rnum = $row["Rnum"];
print "<font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
print " $Rank</font><BR>";
print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">";
print " Rank Level $Rnum</font><BR>";
print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">";
print " Rank Info :: $INFO</font><BR>";
print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">";
print " <a href=\"RankAdmin.php?id=$id&action=edit\">Edit</a> ";
print " <a href=\"RankAdmin.php?id=$id&action=delete\">Delete</a></font><BR><BR>";
$row = mysql_fetch_array($result);
}
mysql_free_result ($result);
?>