diff --git a/ajax.php b/ajax.php index 071297b..5e53d56 100644 --- a/ajax.php +++ b/ajax.php @@ -16,19 +16,63 @@ switch($_GET["action"]) { case "add_featurerequest": if (hasval($_POST["title"]) && hasval($_POST["desc"])) { /* Prepared statement, stage 1: prepare */ - if (!($stmt = $mysqli->prepare("INSERT INTO feature_request(title, desc) VALUES (?, ?)"))) { - echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + if (!($stmt = $mysqli->prepare("INSERT INTO feature_request(title, `desc`) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + }else + if (!$stmt->bind_param("ss", $_POST["title"], $_POST["desc"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + }else + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + }else{ + $errormsg = "all values have to be set"; + } + break; + case "insert": + if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; } if (!$stmt->bind_param("sss", $_POST["was"], $_POST["wann"], $_POST["wo"])) { - echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; } if (!$stmt->execute()) { - echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } + }else{ + $errormsg = "all values have to be set"; } + + break; + case "add_lost": + if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"]) && hasval($_POST["contact"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO lost(was, wann, wo, contact) VALUES (?, ?, ?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("ssss", $_POST["was"], $_POST["wann"], $_POST["wo"], $_POST["contact"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + }else{ + $errormsg = "all values have to be set"; + } + break; + case "get_stats"; + echo json_encode(array("status"=>"ok","stats"=>get_stats())); + break; + default: + $errormsg = "action unknown"; break; } -echo json_encode(array("get"=>$_GET,"post"=>$_POST)); +if(empty($errormsg)) + echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"ok","message"=>"added one item")); +else + echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"error","message"=>$errormsg)); ?> \ No newline at end of file diff --git a/templates/lost.php b/templates/lost.php index 12c2cf6..a739832 100644 --- a/templates/lost.php +++ b/templates/lost.php @@ -19,6 +19,15 @@ + + + + +
@@ -26,7 +35,7 @@ Insert Item into DB
-
+

">

@@ -43,14 +52,21 @@ diff --git a/templates/request.php b/templates/request.php index 42c25c3..55ece5b 100644 --- a/templates/request.php +++ b/templates/request.php @@ -16,10 +16,15 @@ -