-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.php
45 lines (42 loc) · 1.34 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
<?php
require_once 'db_connect.php';
if(isset($_GET['id'])){
$id = $_GET['id'];
db();
global $link;
$query = "SELECT todoTitle, todoDescription FROM tasks WHERE id = '$id'";
$result = mysqli_query($link, $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 task!";
}
if(isset($_POST['submit'])){
$title = $_POST['title'];
$description = $_POST['description'];
db();
$query = "UPDATE tasks SET todoTitle = '$title', todoDescription = '$description' WHERE id = '$id'";
$insertEdited = mysqli_query($link, $query);
if($insertEdited){
echo "Task updated";
}
else{
echo mysqli_error($link);
}
}
}