So, mein Problem ist:
Ich erzeuge einen User, dem ich eine bestimmte Abteilung zuordne. Wenn ich den user editieren will, dann wählt er aber nicht automatisch die von mir ausgewählte
Abteilung aus, sondern nimmt gleich den ersten. Hier der Code. Ich weiß nicht, wie ich das Lösen soll.
Ich erzeuge einen User, dem ich eine bestimmte Abteilung zuordne. Wenn ich den user editieren will, dann wählt er aber nicht automatisch die von mir ausgewählte
Abteilung aus, sondern nimmt gleich den ersten. Hier der Code. Ich weiß nicht, wie ich das Lösen soll.
PHP-Code:
<?
$intSecurity = 0;
$intTimeOut = 900;
$intSecFolder = TRUE;
$strPageTitle = "Edit a User";
Include("../includes/security.inc.php");
Include("../includes/functions.inc.php");
Include("../includes/db.inc.php");
If ($HTTP_POST_VARS["btnSubmit"] != "") {
$strUserID = validateText("User ID", $txtUserID, 3, 20, TRUE, FALSE);
$strFirstName = validateText("First Name", $txtFirstName, 2, 40, TRUE, FALSE);
$strMiddleInit = validateText("Middle Initial", $txtMiddleInit, 1, 1, FALSE, FALSE);
$strLastName = validateText("Last Name", $txtLastName, 2, 40, TRUE, FALSE);
$strEmail = validateEmail("Email Address", $txtEmail, TRUE);
If ($cboLevel == "" AND $strError == "") {
$strError = "Please select a security level.";
}
If($cboAbteilung == "" AND $strError == "") {
$strError = "Please select a department.";
} Else {
$intAbteilung = $cboAbteilung;
}
If ($strError == "") {
$strSQL = "SELECT id FROM tblSecurity WHERE userID='$strUserID' AND NOT id=".$editID;
$result = dbquery($strSQL);
$intFound = mysql_num_rows($result);
If ($intFound != 0) {
$strError = "That userID already exists.";
} Else {
$strSQL = "SELECT id FROM tblSecurity WHERE email='$strEmail' AND NOT id=".$editID;
$result = dbquery($strSQL);
$intFound = mysql_num_rows($result);
If ($intFound != 0) {
$strError = "That email address already exists.";
} Else {
$strSQL = "UPDATE tblSecurity SET userID='$strUserID', firstName='$strFirstName', middleInit='$strMiddleInit', lastName='$strLastName', email='$strEmail', securityLevel=$cboLevel, fk_abteilung=$cboAbteilung WHERE id=".$editID;
$result = dbquery($strSQL);
$strError = "This account has been updated successfully.";
}
}
}
} Else {
$strSQL = "SELECT userID, firstName, middleInit, lastName, email, securityLevel, fk_abteilung FROM tblSecurity WHERE id=".$editID;
$result = dbquery($strSQL);
$row = mysql_fetch_row($result);
$strUserID = $row[0];
$strFirstName = $row[1];
$strMiddleInit = $row[2];
$strLastName = $row[3];
$strEmail = $row[4];
$cboLevel = $row[5];
$cboAbteilung = $row[6];
}
Include("../includes/header.inc.php");
declareError(TRUE);
?>
<form name="form1" method="POST" action="editUser.php">
<p><table border='0' width='406' cellpadding='2'>
<tr>
<td width='106'>UserID:</td>
<td width='300'><input type="text" name="txtUserID" value="<?echo $strUserID;?>" size="20" maxlength="20"></td>
</tr>
<tr>
<td width='106'>First Name:</td>
<td width='300'><input type="text" name="txtFirstName" value="<?echo $strFirstName;?>" size="40" maxlength="40"></td>
</tr>
<tr>
<td width='106'>Middle Initial:</td>
<td width='300'><input type="text" name="txtMiddleInit" value="<?echo $strMiddleInit;?>" size="1" maxlength="1"></td>
</tr>
<tr>
<td width='106'>Last Name:</td>
<td width='300'><input type="text" name="txtLastName" value="<?echo $strLastName;?>" size="40" maxlength="40"></td>
</tr>
<tr>
<td width='106'>Email:</td>
<td width='300'><input type="text" name="txtEmail" value="<?echo $strEmail;?>" size="40" maxlength="50"></td>
</tr>
<tr>
<td width='106'>Security Level:</td>
<td width='300'>
<select name='cboLevel'>
<option value=''> </option>
<option value='0' <? echo writeSelected($cboLevel, "0"); ?>>Full-access</option>
<option value='1' <? echo writeSelected($cboLevel, "1"); ?>>Limited-access</option>
<option value='2' <? echo writeSelected($cboLevel, "2"); ?>>Read-only</option>
<option value='3' <? echo writeSelected($cboLevel, "3"); ?>>No-access</option>
</select>
</td>
</tr>
<tr>
<td width='115'>Department:</td>
<td width='300'>
<select name='cboAbteilung'>
<?
$db = mysql_connect('localhost' ,'inventory', '20074054');
$res = mysql_db_query("inventory", "select * from Abteilung");
echo "<option value=''> </option>\n";
while($row = mysql_fetch_array($res)){
echo "<option value='$row[id_abteilung]'";
if ($row[id_abteilung] == $intAbteilung)
{
echo " selected ";
}
echo ">$row[name]</option>\n";
}
mysql_close($db);
?>
</select>
</td>
</tr>
</table><p>
<input type="hidden" value="<? echo $editID; ?>" name="editID">
<input type="submit" value="Submit" name="btnSubmit">
<input type="reset" value="Reset" name="reset">
</form>
<?
Include("../includes/footer.inc.php");
?>
Kommentar