-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
58 lines (53 loc) · 1.57 KB
/
edit.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
<!DOCTYPE html>
<html>
<head>
<title>Edit Todo</title>
<link rel="stylesheet" type="text/css" media="screen" href="todo.css" />
</head>
<body>
<div style="text-align:left;font-size:250% ;background-color:rgb(243, 199, 56);color:#202013" >
<p>Keep</p>
</div>
<?php
require_once 'database.php';
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = "SELECT todoTitle, todoDescription FROM todo WHERE id = '$id'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result)==1){
$row=mysqli_fetch_array($result);
if($row){
$title = $row['todoTitle'];
$description = $row['todoDescription'];
echo "
<h2>Edit Todo</h2>
<form action='edit.php?id=$id' method='post'>
<p>Title</p>
<input type='text' name='title' value='$title'>
<p>Description</p>
<input type='text' name='description' value='$description'>
<br>
<input type='submit' name='submit' value='edit'>
</form>
";
}
}else{
echo "No todo";
}
if(isset($_POST['submit'])){
$title = $_POST['title'];
$description = $_POST['description'];
$query = "UPDATE todo SET todoTitle = '$title', todoDescription = '$description' WHERE id = '$id'";
$insertEdited = mysqli_query($conn, $query);
if($insertEdited){
echo "Edited sucessfully";
}
else{
echo mysqli_error($conn);
}
}
}
?>
</div>
</body>
</html>