-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNumber_Recognition_Add_Remove_Edit_DB.php
More file actions
57 lines (51 loc) · 1.66 KB
/
Number_Recognition_Add_Remove_Edit_DB.php
File metadata and controls
57 lines (51 loc) · 1.66 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
<?php
require_once "menu_bar.php";
echo "<pre>";
$fileName = "number_recognition_DB.txt";
$myFilePath="./".$fileName;
$myFile = fopen(getcwd()."/".$fileName, "a+");
$fileContents = file_get_contents($myFilePath, NULL);
//variable $myFile holds the addition database
extract($_POST);
$number=$_POST['number'];
$digit=$_POST['digit'];
$place=strtolower($_POST['place']);
$line = "".$number." ".$digit." ".$place."\n";
if (isset ($_POST['add_problem'])){
if ($number =="" or $digit == "" or !isset($place)){
echo "Incomplete problem information, please fill all fields and try again.";
header("refresh:3; url=add_remove_problem_number_recognition.php");
}
//if we get here, that means that all fields are entered
elseif (strpos($fileContents, ($line)) !== false){
echo "Problem already exists in problem set!";
}
//if we get
else {
//add the line to the contents of the file
echo "success";
//echo $fileContents."<br>"."past";
$fileContents = $fileContents.$line;
//overwrite the old file
file_put_contents($fileName, $fileContents);
}
}
elseif (isset($_POST['remove_problem'])){
if ($number =="" or $digit == "" or !isset($place)){
echo "Incomplete problem information, please fill all fields and try again.";
header("refresh:3; url=add_remove_problem_number_recognition.php");
}
//if we get here, that means that all fields are entered
elseif (strpos($fileContents, ($line)) == false){
echo "Problem does not exist in problem set, please try again.";
}
//if we get
else {
echo "successfully removed problem";
//get rid of the line
str_replace($line, "", $fileContents);
//overwrite the old file
file_put_contents($fileName, $fileContents);
}
}
?>