-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathedit.php
More file actions
89 lines (76 loc) · 2.65 KB
/
Copy pathedit.php
File metadata and controls
89 lines (76 loc) · 2.65 KB
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
<?php
// including the database connection file
include_once("Database.php");
if(isset($_POST['update']))
{
$dateexpense=$_POST['dateexpense'];
$item=$_POST['item'];
$details=$_POST['details'];
$costitem=$_POST['costitem'];
if(empty($dateexpense) || empty($item) || empty($details) || empty($costitem) ) {
if(empty($dateexpense)) {
echo "<font color='red'>dateexpense field is empty.</font><br/>";
}
if(empty($item)) {
echo "<font color='red'>item field is empty.</font><br/>";
}
if(empty($details)) {
echo "<font color='red'>details field is empty.</font><br/>";
}
if(empty($costitem)) {
echo "<font color='red'>costitem field is empty.</font><br/>";
}
} else {
//updating the table
$result = mysqli_query($mysqli, "UPDATE users SET dateexpense='$dateexpense',item='$item',details='$details',costitem='$costitem' WHERE id=$id");
//redirectig to the display page. In our case, it is index.php
header("Location: index.php");
}
}
?>
<?php
//getting id from url
$id = $_GET['id'];
//selecting data associated with this particular id
$result = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id");
while($res = mysqli_fetch_array($result))
{
$dateexpense = $res['dateexpense'];
$item = $res['item'];
$details = $res['details'];
$costitem = $res['costitem'];
}
?>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<a href="index.php">Home</a>
<br/><br/>
<form name="form1" method="post" action="edit.php">
<table border="0">
<tr>
<td>dateexpense</td>
<td><input $type="text" $name="dateexpense" $value="<?php echo $dateexpense;?>"></td>
</tr>
<tr>
<td>item</td>
<td><input $type="text" $name="item" $value="<?php echo $item;?>"></td>
</tr>
<tr>
<td>details</td>
<td><input $type="text" $name="details" $value="<?php echo $details;?>"></td>
</tr>
<tr>
<td>costitem</td>
<td><input $type="value" $name="costitem" $value="<?php echo $costitem;?>"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value='<?php echo $_GET['id'];?>'></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>