I am losing data from my $username variable in the code below. I've racked my brains and I cannot find the error.
This is edit.php, it calles editact.php
<?php
include('include/database.php');
include('include/pre.php');
include('include/user.php');
/
if (user_isloggedin()) {
user_logout();
$user_name='';
}
/
site_header("Edit Members");
printf("<H2>Select the Username you would like to edit.</h2>");
printf("<form action=editact.php method=post>");
printf("<select name=username>\n");
$sql="select * from users";
$result=db_query($sql);
while ($myrow = mysql_fetch_array($result)) {
printf("<option value='$myrow[username]'>$myrow[username]</option>\n");
}
printf("</select>");
printf("<input type=\"submit\" value=\"Edit Info\">");
printf("</form>");
site_footer();
?>
This is editact.php:
<?php
include('include/database.php');
include('include/pre.php');
include('include/user.php');
if ($submit) {
user_change_info($username,$memberstat,$race,$class,$level,$email,$id);
// printf("$username was updated successfully.");
}
if ($feedback) {
echo '<FONT COLOR="Yellow"><H2>'. $feedback .'</H2></FONT>';
exit;
}
site_header("Edit $username's information");
$sql="select * from users where username='$username'";
$result=db_query($sql);
if ($result && db_numrows($result) < 1) {
printf('<h2><font color=yellow>ERROR -' .db_error());
return false;
} else {
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$username = $myrow["username"];
$memberstat = $myrow["memberstat"];
$race = $myrow["race"];
$class = $myrow["class"];
$level = $myrow["level"];
$email = $myrow["email"];
echo '<H3>Edit Information:</H3>
<P>
Change the incorrect info and resubmit.
<P>
<FORM ACTION="'. $PHP_SELF .'" METHOD="POST">
<center>
<table border=1 bgcolor=gray>
<th colspan=2 align=center>Edit Account Information</th>
<TR>
<tr>
<td><B><font color=black>Username:</B></td>
<td><INPUT TYPE="text" NAME="username" VALUE="'. $username .'" SIZE="35" MAXLENGTH="35"></td>
</tr>
<tr>
<td><B><font color=black>Member Status:</B></td>
<td><INPUT TYPE="TEXT" NAME="memberstat" VALUE="'. $memberstat .'" SIZE="35" MAXLENGTH="35"></td>
</tr>
<tr>
<td><B><font color=black>Race:</B></td>
<td><INPUT TYPE="text" NAME="race" VALUE="'. $race .'" SIZE="35" MAXLENGTH="25">'. $alliance .'</td>
</tr>
<tr>
<td><B><font color=black>Class:</B></td>
<td><INPUT TYPE="TEXT" NAME="class" VALUE="'. $class .'" SIZE="10" MAXLENGTH="15"></td>
</tr>
<tr>
<td><B><font color=black>Level:</B></td>
<td><INPUT TYPE="TEXT" NAME="level" VALUE="'. $level .'" SIZE="10" MAXLENGTH="15"></td>
</tr>
<tr>
<td><B><font color=black>Email:</B></td>
<td><INPUT TYPE="TEXT" NAME="email" VALUE="'. $email .'" SIZE="20" MAXLENGTH="50"></td>
<input type="hidden" name="id" value="'. $id .'">
</tr>
<tr>
<td colspan=2 align=center>
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Update Alliance Registry">
</td>
</tr>
</table>
</FORM>
';
}
site_footer();
?>
This is the function called by editact.php:
function user_change_info ($username,$memberstat,$race,$class,$level,$email,$id) {
global $feedback;
$sql="update users set username='$usersname',memberstat='$memberstat',race='$race',class='$class',
level='$level',email='$email' where id='$id'";
$result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$feedback .= ' Nothing Changed '.db_error();
return false;
} else {
$feedback .= ' Info Updated ';
return true;
}
}
To give credit, a large majority of this code was taken from the snippet library and adopted to fit my needs.