I created this form with PHP and MySQL. Whenever I submit the form and click update button it is showing unsucess. I don't know what is going wrong and I need help finding the problem. I've attached the code below.
<?php
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
$con = mysqli_connect("localhost","root","") or die("unable to connect");
mysqli_select_db($con,'studentdb');
if(isset($_GET['registernumber']))
$registernumber = html_entity_decode($_GET['registernumber']);
$query= "SELECT * FROM studenttble WHERE registernumber='$registernumber'";
$query_run = mysqli_query($con,$query);
while($row = mysqli_fetch_array($query_run, MYSQL_ASSOC))
{
$IID = $row['IID'];
$studentname = $row['studentname'];
$fathername = $row['fathername'];
$registernumber = $row['registernumber'];
$year = $row['$year'];
$dept = $row['$dept'];
$section = $row['section'];
$gender = $row['gender'];
$password = $row['password'];
$email = $row['email'];
$dob = $row['dob'];
$raddress = $row['raddress'];
$mnumber = $row['mnumber'];
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" id="form1" class="myform">
<table align="center">
<tr>
<td>
<input name="estudentname" type="text" id="studentname" class="wp-form-control wpcf7-text" value="<?php echo $studentname?>" />
</td>
</tr>
<br>
<tr>
<td>
<input name="efathername" type="text" id="fathername" class="wp-form-control wpcf7-text" value="<?php echo $fathername?>" />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="registernumber" id="registernumber" class="wp-form-control wpcf7-text" value="<?php echo $registernumber?>" placeholder="Register Number" />
</td>
</tr>
<tr>
<td>
<input type="text" name="egender" id="gender" class="wp-form-control wpcf7-text" value="<?php echo $gender?>" />
</td>
</tr>
<tr>
<td><input type="text" name="eemail" type="email" id="email" class="wp-form-control wpcf7-text" value="<?php echo $email?>" />
</td>
</tr>
<tr>
<td>
<h3 class="table">Date Of Birth: <input type="text" name="edob" id="dob" type="date" class="dropdown-menu-left" value="<?php echo $dob?>" max="2017-02-08"/></td></tr>
</h3>
<tr>
<td> <input type="text" class="wp-form-control wpcf7-textarea" name="eraddress" cols="30" rows="10" value="<?php echo $raddress?>"></textarea>
</td>
</tr>
<tr>
<td> <input name="emnumber" type="text" id="mnumber" pattern="[789][0-9]{9}" class="wp-form-control wpcf7-text" max="10" value="<?php echo $mnumber?>" />
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="update" class="wpcf7-submit" value="update">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['update']))
{
$con = mysqli_connect("localhost","root","") or die("unable to connect");
mysqli_select_db($con,'studentdb');
$estudentname = mysql_real_escape_string($_POST['estudentname']);
$efathername = mysql_real_escape_string($_POST['efathername']);
$egender = mysql_real_escape_string($_POST['egender']);
$eemail = mysql_real_escape_string($_POST['eemail']);
$edob = mysql_real_escape_string($_POST['edob']);
$eraddress = mysql_real_escape_string($_POST['eraddress']);
$emnumber = mysql_real_escape_string($_POST['emnumber']);
$targetid = mysqli_real_escape_string($_POST['registernumber']);
mysqli_select_db('studentdb');
$query = "UPDATE studenttble SET studentname ='$estudentname', fathername ='$efathername', gender ='$egender', email ='$eemail', dob ='$edob', raddress ='$eraddress', mnumber ='$emnumber' WHERE registernumber ='$targetid'";
$retval = mysqli_query( $query, $conn );
if($retval)
{
echo "sucess";
}
else
{
echo "unsucess";
}
}
?>