Forum Moderators: coopster
everything seems fine. when i edit the fields and submit the form everything goes fine. but if i only edit some of the fields the ones i dont edit update blank.
--------------------------------
i have a table called items with the fields
id - unique key - int
name - text
type - int
level - int
prof - int
npc - int
descr - text
planet - int
zone - int
quest - int
status - emnu
owner - int
------------------------------------
this is the bottom half of my itemdetails.php which had the form to edit data
---------------------
function genrelisttype() {
$ret1 = array();
$res1 = mysql_query("SELECT id, name FROM type ORDER BY name");
while ($row1 = mysql_fetch_array($res1))
$ret1[] = $row1;
return $ret1;
}
function genrelistprof() {
$ret2 = array();
$res2 = mysql_query("SELECT id, name FROM prof ORDER BY name");
while ($row2 = mysql_fetch_array($res2))
$ret2[] = $row2;
return $ret2;
}
function genrelistnpc() {
$ret3 = array();
$res3 = mysql_query("SELECT id, name FROM npcs ORDER BY name");
while ($row3 = mysql_fetch_array($res3))
$ret3[] = $row3;
return $ret3;
}
function genrelistplanet() {
$ret4 = array();
$res4 = mysql_query("SELECT id, name FROM planet ORDER BY name");
while ($row4 = mysql_fetch_array($res4))
$ret4[] = $row4;
return $ret4;
}
function genrelistzone() {
$ret5 = array();
$res5 = mysql_query("SELECT id, name FROM zone ORDER BY name");
while ($row5 = mysql_fetch_array($res5))
$ret5[] = $row5;
return $ret5;
}
function genrelistquest() {
$ret6 = array();
$res6 = mysql_query("SELECT id, name FROM quest ORDER BY name");
while ($row6 = mysql_fetch_array($res6))
$ret6[] = $row6;
return $ret6;
}
if (get_user_class() >= UC_MODERATOR && $user["class"] < get_user_class())
{
begin_frame("Edit User - <font color=#004E98>Viewable by Mods only.</font>", true);
print("<div align=\"Center\">\n");
print("<form action=\"edititem.php\" method=\"post\">\n");
print("<input type=hidden name=\"itemid\" value=\"$id\">\n");
print("<input type=hidden name=\"returnto\" value=\"itemdetails.php?id=$id\">\n");
print("<table border=\"1\" cellspacing=\"0\" cellpadding=\"10\">\n");
tr("Item name", "<input type=\"text\" name=\"name\" size=\"100\" value=\"$items[name]\" />\n", 1);
// type drop down
$s1 = "<select name=\"type\">\n<option value=\"0\">$type</option>\n";
$types1 = genrelisttype();
foreach ($types1 as $row1)
$s1 .= "<option value=\"" . $row1["id"] . "\">" . htmlspecialchars($row1["name"]) . "</option>\n";
$s1 .= "</select>\n";
tr("Type", $s1, 1);
tr("Level", "<input type=\"text\" name=\"level\" size=\"5\" value=\"$items[level]\" />\n", 1);
// prof drop down
$s2 = "<select name=\"prof\">\n<option value=\"0\">$prof</option>\n";
$prof2 = genrelistprof();
foreach ($prof2 as $row2)
$s2 .= "<option value=\"" . $row2["id"] . "\">" . htmlspecialchars($row2["name"]) . "</option>\n";
$s2 .= "</select>\n";
tr("Profession", $s2, 1);
//end prof
// npc drop down
$s3 = "<select name=\"npc\">\n<option value=\"0\">$npc</option>\n";
$npc3 = genrelistnpc();
foreach ($npc3 as $row3)
$s3 .= "<option value=\"" . $row3["id"] . "\">" . htmlspecialchars($row3["name"]) . "</option>\n";
$s3 .= "</select>\n";
tr("NPC", $s3, 1);
$descr = htmlspecialchars($items["descr"]);
print("<tr><td class=rowhead>Decription</td><td colspan=2 align=left><textarea cols=60 rows=6 name=descr>$descr</textarea><br>(HTML/BB code is <b>not</b> allowed.)</td></tr>\n");
//tr("Description", "<textarea name=\"descr\" rows=\"10\" cols=\"80\" value=\"$descr\"></textarea>" .
//print("<br>(HTML/BB code is <b>not</b> allowed.), 1");
// planet drop down
$s4 = "<select name=\"planet\">\n<option value=\"0\">$planet</option>\n";
$planet4 = genrelistplanet();
foreach ($planet4 as $row4)
$s4 .= "<option value=\"" . $row4["id"] . "\">" . htmlspecialchars($row4["name"]) . "</option>\n";
$s4 .= "</select>\n";
tr("Planet", $s4, 1);
//end planet
// zone drop down
$s5 = "<select name=\"zone\">\n<option value=\"0\">$zone</option>\n";
$zone5 = genrelistzone();
foreach ($zone5 as $row5)
$s5 .= "<option value=\"" . $row5["id"] . "\">" . htmlspecialchars($row5["name"]) . "</option>\n";
$s5 .= "</select>\n";
tr("Zone", $s5, 1);
//end zone
// quest drop down
$s6 = "<select name=\"quest\">\n<option value=\"0\">$quest</option>\n";
$quest6 = genrelistquest();
foreach ($quest6 as $row6)
$s6 .= "<option value=\"" . $row6["id"] . "\">" . htmlspecialchars($row6["name"]) . "</option>\n";
$s6 .= "</select>\n";
tr("Quest", $s6, 1);
//end quest
?>
<tr><td align="center" colspan="2"><input type="submit" class=btn value="submit" /></td></tr>
</table>
</form>
<?
end_frame();
}
end_main_frame();
stdfoot();
?>
----------------------------------
here is my edititems.php which updates the tables
------------------------------------------
require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
if (get_user_class() < UC_UPLOADER)
die;
$id = $_POST['itemid'];
$name = $_POST['name'];
$type = $_POST['type'];
$level = $_POST['level'];
$prof = $_POST['prof'];
$npc = $_POST['npc'];
$descr = $_POST['descr'];
$planet = $_POST['planet'];
$zone = $_POST['zone'];
$quest = $_POST['quest'];
//$isubby = $CURUSER["id"];
$query = "UPDATE items SET name='$name', type='$type', level='$level', prof='$prof', npc='$npc', descr='$descr', planet='$planet', zone='$zone', quest='$quest' WHERE id='$id'";
stdhead("Data Submitted");
mysql_query ( $query ) or die("Sorry!.. Your data could not be submitted.... Please quote this message to a sysop if this continues: " . mysql_error());
print("<h1>Thank you! Your data has been submitted and added to the database.</h1><p>");
print("<a href='$BASEURL/swgloot/itemdetails.php?id=$id'>RETURN BACK TO THE ITEM</a>");
stdfoot();
?>
[edited by: Mopreme at 9:16 pm (utc) on Sep. 20, 2008]