You are on page 1of 3

<?

php
include_once 'database.php';
$edit=$_GET['id'];
$select="select * from student where id='$edit'";
$run=mysqli_query($con,$select);
$row=mysqli_fetch_array($run);

$id=$row['id'];
$name=$row['name'];
$gender=$row['gender'];
$a=$row['hobby'];
$hobby=explode(',',($a));
$course=$row['course'];
$college=$row['college'];
$contact=$row['contact'];
$image=$row['image'];

?>
<html>
<head>
<title>Student Record Update</title>
</head>
<body>

<form action="update.php?id=<?php echo $row['id'];?>" method="post"


enctype='multipart/form-data'>
<table align="center" border="1" width="600">
<tr>
<th colspan="2" style="height:50px;background:yellow;">Student
Record Update</th>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value="<?php echo $name;?>"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" name="gender" value="Male"
<?php
if($gender=='Male'){
echo "checked";
}
?>
>Male
<input type="radio" name="gender" value="Female"
<?php
if($gender=='Female'){
echo "checked";
}
?>
>Female
</td>
</tr>
<tr>
<td>Hobby:</td>
<td>
<input type="checkbox" name="hobby[]" value="Traveling"
<?php
if(in_array('Traveling',$hobby))
{
echo "checked";
}
?>
>Traveling
<input type="checkbox" name="hobby[]" value="Dancing"
<?php
if(in_array('Dancing',$hobby))
{
echo "checked";
}
?>
>Dancing
</td>
</tr>
<tr>
<td>Course</td>
<td><select name="course">
<option><?php echo $course;?></option>
<option>bsc</option>
<option>bca</option>
</td>
</tr>
<tr>
<td>College:</td>
<td><input type="text" name="college" value="<?php echo $college;?>"></td>
</tr>
<tr>
<td>Contact:</td>
<td><input type="text" name="contact" value="<?php echo $contact;?>"></td>
</tr>
<tr>
<td>Image</td>
<td>
<img src="upload/<?php echo $row['image'];?>" height="50" width="50">
<input type="file" name="image">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="update" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

<?php

if(isset($_POST['update'])){

$up_id=$_GET['id'];
$name_u=$_POST['name'];
$gender_u=$_POST['gender'];
$b=$_POST['hobby'];
$hobby_u=implode(',',($b));
$course_u=$_POST['course'];
$college_u=$_POST['college'];
$contact_u=$_POST['contact'];
if(isset($_FILES['image']['name'])&&($_FILES['image']['name']!=""))
{
$file_name=$_FILES['image']['name'];
$file_size=$_FILES['image']['size'];
$file_tmp=$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
unlink("image,$old_image");
move_uploaded_file($file_tmp,"upload/".$file_name);
}
else{
$file_name=$old_image;
}

$update="update student set


name='$name_u',gender='$gender_u',hobby='$hobby_u',course='$course_u',college='$col
lege_u',contact='$contact_u',image='$file_name' where id='$up_id'";

$run_u=mysqli_query($con,$update);
if($run_u){

//echo "<script>alert('Record Update Successfully.')</script>";


echo "<script>window.open('student.php','_self')</script>";

else{

echo "<script>alert('update failed')</Script>";

}
}
?>

You might also like