I am having a problem with this code. It doesn’t work correctly. It displays all the information from the database ([B]case “edit”[B]case “view”
[code=php] case “edit”:
$sql = “SELECT * FROM user ORDER BY last”;
$sql_query = mysql_query($sql);
echo'<table width=”25%”>
<tr>
<th>Last</th>
<th>First</th>
<th>Session</th>
</tr>’;
while($row = mysql_fetch_array($sql_query)){
echo'<tr>
<td>’.$row[last].'</td>
<td>’.$row[first].'</td>
<td><a class=”contenttxt” href=”‘.$_SERVER[‘PHP_SELF’].’?page=view&user=’.$row[session_id].'”>’.$row[session_id].'</a></td>
</tr>’;
}
echo'</table>’;
break;
case “view”:
if(!isset($_POST[‘submit’])){
$sql = “SELECT * FROM user WHERE session_id=’$_GET[user]'”;
$sql_query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($sql_query);
echo'<form action=”‘.$_SERVER[‘PHP_SELF’].’?page=view&user=’.$_GET[user].'” method=”post”>
<table>
<tr>
<td>First Name:</td>
<td><input type=”text” name=”first” value=”‘.$row[‘first’].'”></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=”text” name=”last” value=”‘.$row[‘last’].'”></td>
</tr>
<tr>
<td>Session Number:</td>
<td><input type=”text” name=”number” value=”‘.$row[‘session_id’].'”></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=”text” name=”password” value=”‘.$row[‘password’].'”></td>
</tr>
<tr>
<td colspan=”2″><input type=”submit” name=”submit” value=”Change”></td>
</tr>
</table>
</form>’;
}else{
if($_SESSION[‘id’] != 1){
echo'<h2>You don’t have access</h2>’;
}else{
mysql_query(“UPDATE user SET first=’$_POST[first]’, last=’$_POST[last]’, session_id=’$_POST[number]’, password=’$_POST[password]’ WHERE session_id=’$_POST[number]'”)or die(mysql_error());
echo’Information Successfully Changed.’;
}
}
break;