Hi everyone..im new to php and dont know much about my sql as well.actually i have displayed a mysql table from database to my webpage using php.now i've got a seperate list of teachers with thier data(firstname, last name,email, type).what i want is to edit a specific record from the table and want to change the record of that teacher when i press edit button of that specific teacher.or delete the same teacher when i press the delete button.here is my code.its not showing me the specific teacher's record but only showing the first row record of the database. please help me to understand and solve this problem.thankx in advance
this is teachers-list.php
<?php include("../includes/config.php"); ?>
<!DOCTYPE HTML>
<html>
<head>
<title>Admdin Home</title>
<link rel="StyleSheet" href="css/style.css" type="text/css" media="screen">
</head>
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<?php include("includes/aside.php"); ?>
<div id="maincontent">
<div id="breadcrumbs">
<a href="">Home</a> >
<a href="">Manage Users</a> >
List Users
</div>
<h2>Teachers List</h2>
</div>
<?php
if ($_SESSION["isadmin"])
{
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM accounts WHERE (type='T')");
echo "<table border='1'>
<tr>
<th>E-mail</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Type</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td><a href='edit-teacher.php'>EDIT</a></td> <td><a href='edit-teacher.php'>DELETE</a></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
<?php include("includes/footer.php"); ?>
</html>
<?php
}
else
{
header("Location: ".$fullpath."login/unauthorized.php");
}
?>
this is edit-teacher.php
<?php include("../includes/config.php"); ?>
<?php
if ($_SESSION["isadmin"])
{
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM accounts WHERE (id=".$_SESSION["id"].")");
while($row = mysql_fetch_array($result))
{
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email=$row['email'];
$type=$row['type'];
}
mysql_close($con);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Change Password</title>
<link rel="StyleSheet" href="../admin/css/style.css" type="text/css" media="screen">
</head>
<body>
<?php include("../admin/includes/header.php"); ?>
<?php include("../admin/includes/nav.php"); ?>
<?php include("../admin/includes/aside.php"); ?>
<div id="maincontent">
<div id="breadcrumbs">
<a href="">Home</a> >
<a href="">Manage Users</a> >
<a href="">List Users</a> >
Edit Teacher
</div>
<h2>Edit Teacher</h2>
<?php
if (isset($_GET["status"]))
{
if ($_GET["status"]==1)
{
echo("<strong>Teacher Has been Successfully Edited!</strong>");
}
}
?>
<form method="post" action="edit-teacher-action.php">
<label>First Name:</label> <input type="text" value="<?php echo $firstname; ?>" name="Fname" />
<label>Last Name:</label> <input type="text" value="<?php echo $lastname; ?>" name="Lname" />
<label>Email:</label> <input type="text" value="<?php echo $email; ?>" name="email" />
<label>Type:</label> <input type="text" value="<?php echo $type; ?>" name="type" />
<input type="submit" value="Edit" />
</form>
</div>
</body>
<?php include("../admin/includes/footer.php"); ?>
</html>
<?php
}
else
{
header("Location: ".$fullpath."login/unauthorized.php");
}
?>
this is edit-teacher-action.php
<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$email=$_POST["email"];
$type=$_POST["type"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' email='".$email."' type='".$type."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: edit-teacher.php?status=1");
mysql_close($con);
?>