-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.php
More file actions
52 lines (44 loc) · 1.8 KB
/
todo.php
File metadata and controls
52 lines (44 loc) · 1.8 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
<html>
<head>
<title>ToDo Page</title>
</head>
<body>
<form method="post"><input type="submit" name="reset" value="reset"></form>
<form method="post">
Item: <input type="text" name="input1" />
<input type="submit" value="Add">
</form>
<form method="post">
up_num: <input type="text" name="up_num" />
Item: <input type="text" name="up_item" />
<input type="submit" name="update" value="update">
</form>
<ol>
<?php
session_start();
if(isset($_REQUEST["reset"]))
{
unset($_SESSION["array1"]);
session_destroy();
}
$array1 = array(); // create an empty array
if(isset($_SESSION["array1"])) // check if the session variable exists
$array1 = $_SESSION["array1"]; // get the array from the session
if(isset($_REQUEST["input1"]))
{
$input1 = $_REQUEST["input1"];
array_push($array1, $input1); // add the new item to the array
}
if(isset($_REQUEST["update"]))
{
$up_num=intval($_REQUEST["up_num"]);
$up_item = $_REQUEST["up_item"];
$array1[$up_num] = $up_item;
}
foreach($array1 as $item)
echo "<li><input type='radio' name='radio1' value='$item'/>$item</li>";
$_SESSION["array1"] = $array1; // save the array back to the session
?>
</ol>
</body>
</html>