-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedit.php
71 lines (64 loc) · 1.89 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
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
//get the index from URL
$index = $_GET['index'];
//get json data
$data = file_get_contents('lista.json');
$data_array = json_decode($data);
//assign the data to selected index
$row = $data_array[$index];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<title>Operații CRUD pe fișiere JSON TipueSearch folosind PHP</title>
</head>
<body>
<br />
<div class="container">
<form method="POST">
<p><a class="btn btn-primary btn-lg btn-sm" href="index.php">Înapoi</a></p>
<p>
<label for="title">Title</label>
<input type="text" id="title" name="title" value="<?php echo $row->title; ?>">
</p>
<p>
<label for="text">Text</label>
<input type="text" class="form-control" id="text" name="text" value="<?php echo $row->text; ?>">
</p>
<p>
<label for="tags">Tags</label>
<input type="text" class="form-control" id="tags" name="tags" value="<?php echo $row->tags; ?>">
</p>
<p>
<label for="url">URL</label>
<input type="text" class="form-control" id="url" name="url" value="<?php echo $row->url; ?>">
</p>
<input class="btn btn-primary btn-lg btn-sm" type="submit" name="save" value="Save">
</form>
</div>
<?php
if(isset($_POST['save'])){
//set the updated values
$input = array(
'title' => $_POST['title'],
'text' => $_POST['text'],
'tags' => $_POST['tags'],
'url' => $_POST['url']
);
//update the selected index
$data_array[$index] = $input;
//reordering array
$data_array = array_values($data_array);
//encode back to json
$data = json_encode($data_array, JSON_PRETTY_PRINT);
file_put_contents('lista.json', $data);
header('location: index.php');
}
?>
</body>
</html>