-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.php
93 lines (69 loc) · 2.43 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
include 'includes/db.php';
?>
<?php
if(isset($_GET['update'])){
$id = $_GET['update'];
$query = "SELECT * FROM student WHERE id = $id";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$name = $row['name'];
$batch = $row['batch'];
$email = $row['email'];
$image = $row['image'];
}
}
}
if(isset($_POST['update'])){
$name = clean($_POST['name']);
$batch = clean($_POST['batch']);
$email = clean($_POST['email']);
$image_name = $_FILES['image']['name'];
$image = $_FILES['image']['tmp_name'];
$location = "images/".$image_name;
move_uploaded_file($image, $location);
$query = "UPDATE student SET ";
$query .= "name = '".escape($name)."', ";
$query .= "batch = '".escape($batch)."', ";
$query .= "email = '".escape($email)."', ";
$query .= "image = '{$image_name}' ";
$query .= "WHERE id = {$id} ";
$result = mysqli_query($conn,$query);
if($result){
header('location:index.php');
}
else
{
die('error' . mysql_error($conn));
}
}
?>
<div class="container">
<div class="jumbotron text-center">
<h2>Crud Application Using PHP</h2>
</div>
<br>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" name="name" class="form-control" placeholder="Enter Name" value="<?php echo $name ?>">
</div>
<div class="form-group">
<label for="name">Batch:</label>
<input type="text" name="batch" class="form-control" placeholder="Enter batch" value="<?php echo $batch ?>">
</div>
<div class="form-group">
<label for="name">Email:</label>
<input type="text" name="email" class="form-control" placeholder="Enter email" value="<?php echo $email ?>">
</div>
<div class="form-group">
<label for="name">Image:</label>
<img src= "<?= "images/".$image?>" alt="" width="100px" height="100px" class="thumbnail">
<input type="file" name="image" class="form-control" placeholder="Enter email" value="<?php echo $email ?>">
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" value="Update data" name="update">
</div>
</form>
</div>