Click here to Skip to main content
14,735,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello dear, i know my code is deprecated but iam still newbie who want to know learning php using old method before using PDO or mySQLi. i had an issue in my script code but i cant track where the problem in my script codes. basically i create some admin panel who display all about my users table. This is the code of adminpanel.php :


<?php include "base.php"; ?>
	<?php
	  //if no session go to mainpage
	  if(!$_SESSION['Username']){
	    header('location:index.php');
	  }  
	  //if ssesion is admin access accepted
	  if($_SESSION['privilege'] == 'admin' ){
	 // header('location:adminpanel.php');
	  }
	  //if not access is deny
	  else {
      header('Location: login.php');
      }
	?>
	
<!doctype html>
<html>
<head>
<title>Admin Panel</title>
</head>

<body>

Hai <?=$_SESSION['Username']?>,<br>
Welcome on admin panel..<br><br>
<?php
$result = mysql_query("SELECT * FROM users");
echo "<table border='1'>
<tr>
<th>User ID</th>
<th>Username</th>
<th>Password</th>
<th>Email Address</th>
<th>Privelege</th>
<th>Setting</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['UserID'] . "</td>";
  echo "<td>" . $row['Username'] . "</td>";
  echo "<td>" . $row['Password'] . "</td>";
  echo "<td>" . $row['EmailAddress'] . "</td>";
  echo "<td>" . $row['privilege'] . "</td>";
  echo "<td><a href=\"adminedit.php?id=$row[UserID]\">Edit</a></td>";
  echo "</tr>";
  }
echo "</table><br>";
	
if (!isset($_SESSION['count'])) {
	   $_SESSION['count'] = 0;
	} else {
	   $_SESSION['count']++;
	}
	echo "you have been login to this page " .
	$_SESSION['count']." times";
	echo "<br>";
	echo "Kita kenali Anda sebagai: <br><br>"  .session_id();
	?>
		<br><br><A href='logout.php'>logout</A><br><br>
</body>
</html>


now if i want to edit some user account it will redirected to new page called adminedit.php this is the code :

<?php include "base.php"; 
	  $id = $_GET["id"];
?>

<!DOCTYPE HTML>
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
  <tr>
    <td align=center>Form Edit Data</td>
  </tr>
  	  <?php
      $result = mysql_query("SELECT * FROM users where UserID='$id'");
	  while($row = mysql_fetch_array($result))
	  {
	  $nama =  $row['Username'];
	  $pass =  $row['Password'];
	  $email = $row['EmailAddress'];
	  $privilege = $row['privilege'];
	  }
      ?>
<tr><td>

<?php
if(isset($_POST['submit']))
{
$id = $_POST["id"];
$name = $_POST["username"];
$password = $_POST["password"];
$emailaddress = $_POST["email"];
$privilege = $_POST["privilege"];
$sql = "UPDATE users SET Username='$name', Password='$password', EmailAddress='$emailaddress', privilege='$privilege' WHERE UserID='$id'";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<BR>";
header('location:adminpanel.php');
echo "<a href='adminpanel.php'>View result</a>"; 
}

else {
echo "ERROR";
}

}
?>

<table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<? echo $id;?>">

<tr>        
<td>Username</td>
<td>
<input type="text" name="username" size="80" value="<?php echo $nama;?>">
</td>
</tr>

<tr>
<td>Password</td>
<td>
<input type="text" name="password" size="80" value="<?php echo $pass;?>">
</td>
</tr>

<tr>
<td>Email Address</td>
<td>
<input type="text" name="email" size="80" value="<?php echo $email;?>">
</td>
</tr>

<tr>
<td>Privilege</td>
<td>
<input type="text" name="privilege" size="80" value="<?php echo $privilege?>">
</td>
</tr>

<tr>
<td align="left">
<input type="submit" name="submit" value="Edit">
</td>
</tr>

</form>
</table>
</td></tr>
</table>

</body>
</html>


but when iam click the button to edit some account in the table user nothing changed? would be happy if someone can help me thank you.
Posted
Comments
Sunasara Imdadhusen 27-May-14 7:18am
   
Are you getting any error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900