I am trying to develop an PHP MySQL database application where edit details is not working.I am new to PHP and doing this with the help of various web resources such as youtube videos, tutorials, similar programs etc .I am able to fetch the data from the database, but when it comes to edit, the data remains the same even after changing.Can anyone suggest the solution of this problem.
manage-profile.php
<?php
session_start();
require('connection.php');
//If your session isn't valid, it returns you to the login screen for protection
if(empty($_SESSION['sl_no'])){
header("location:access-denied.php");
}
//retrive student details from the student table
$result=mysqli_query($con, "SELECT * FROM student WHERE sl_no = '$_SESSION[sl_no]'");
if (mysqli_num_rows($result)<1){
$result = null;
}
$row = mysqli_fetch_array($result);
if($row)
{
// get data from db
$stdId = $row['sl_no'];
$stdRoll = $row['roll_no'];
$stdName = $row['name'];
$stdClass = $row['class'];
$stdSex= $row['sex'];
}
?>
<?php
// updating sql query
if (isset($_POST['update'])){
$myId = addslashes( $_GET[$id]);
$myRoll = addslashes( $_POST['roll_no'] );
$myName = addslashes( $_POST['name'] );
$myClass = addslashes( $_POST['class'] );
$myGender = $_POST['sex'];
$sql = mysqli_query($con,"UPDATE student SET roll_no='$myRoll', name='$myName', class='$myClass', sex='$myGender' WHERE sl_no = '$myId'" );
// redirect back to profile
header("Location: manage-profile.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Student Profile Management</title>
<link href="css/student_styles.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="js/user.js">
</script>
</head>
<body bgcolor="#e6e6e6">
<center><b><font color = "black" size="6">Online Voting System</font></b></center><br><br>
<div id="page">
<div id="header">
<h2>Manage Profile</h2>
<a href="student.php">Home</a> | <a href="vote.php">Current Polls</a> | <a href="manage-profile.php">Manage My Profile</a> | <a href="changepassword.php">Change Password</a>| <a href="logout.php">Logout</a>
</div>
<div id="container">
<table border="0" width="620" align="center">
<CAPTION><h3>Update Profile</h3></CAPTION>
<form action="manage-profile.php?$id=<?php echo $_SESSION['sl_no']; ?>" method="post" onsubmit="return updateProfile(this)">
<table align="center">
<tr><td>Roll Number:</td><td><input type="text" style="background-color:#e8daef; font-weight:regular;" name="roll_no" maxlength="50" value="<?php echo $row["roll_no"]; ?>"></td></tr>
<tr><td>Name:</td><td><input type="text" style="background-color:#e8daef; font-weight:regular;" name="Name" maxlength="30" value="<?php echo $row["name"]; ?>"></td></tr>
<tr><td>Class:</td><td><select name='sclass' style='background-color:#e8daef; font-weight:regular;' maxlength='10' id='class' required='true'>
<option value='HS-1st Year'
<?php
if($row["class"]=='HS-1st Year')
{
echo "selected";
}
?>
>HS-1st Year</option>
<option value='HS-2nd Year'
<?php
if($row["class"]=='HS-2nd Year')
{
echo "selected";
}
?>
>HS-2nd Year</option>
<option value='BA-1st Sem'
<?php
if($row["class"]=='BA-1st Sem')
{
echo "selected";
}
?>
>BA-1st Sem</option>
<option value='BA-3rd Sem'
<?php
if($row["class"]=='BA-3rd Sem')
{
echo "selected";
}
?>
>BA-3rd Sem</option>
<option value='BA-5th Sem'
<?php
if($row["class"]=='BA-5th Sem')
{
echo "selected";
}
?>
>BA-5th Sem</option>
<option value='BCom-1st Sem'
<?php
if($row["class"]=='BCom-1st Sem')
{
echo "selected";
}
?>
>BCom-1st Sem</option>
<option value='BCom-3rd Sem'
<?php
if($row["class"]=='BCom-3rd Sem')
{
echo "selected";
}
?>
>BCom-3rd Sem</option>
<option value='BCom-5th Sem'
<?php
if($row["class"]=='BCom-5th Sem')
{
echo "selected";
}
?>
>BCom-5th Sem</option>
</select>
</td></tr>
<tr><td>Sex:</td><td>
<input type='radio' style='background-color:#e8daef; font-weight:regular;' name='gender' id='male' value='Male'
<?php
if($row["sex"]=='Male')
{
echo "checked";
}
?>
>Male<br>
<input type='radio' style='background-color:#e8daef; font-weight:regular;' name='gender' id='female' value='Female'
<?php
if($row["sex"]=='Female')
{
echo "checked";
}
?>
>Female<br></td></tr>
<tr><td> </td></tr><tr><td><input type="submit" name="update" value="Update Profile"></td></tr>
</table>
</form>
</div>
<div id="footer">
<div class="bottom_addr">Student Union Election,Anonymous College</div>
</div>
</body>
</html>