diff --git a/ajax.php b/ajax.php index 07ca083..f37e2e0 100644 --- a/ajax.php +++ b/ajax.php @@ -85,6 +85,44 @@ switch($_GET["action"]) { $errormsg = "all values have to be set"; } break; + case "add_match": + $successmsg = "one match added"; + if (hasval($_POST["found_id"]) && hasval($_POST["lost_id"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("ii", $_POST["found_id"], $_POST["lost_id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + }else if (hasval($_POST["found_id"]) && hasval($_POST["ticket_id"])) { + if (!($stmt = $mysqli->prepare("INSERT INTO lost_items(was) VALUES (?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("s", $_POST["ticket_id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $lost_id = $mysqli->insert_id; + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("ii", $_POST["found_id"], $lost_id)) { + $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; diff --git a/templates/found_item_table.php b/templates/found_item_table.php index 1682c77..a07aaf8 100644 --- a/templates/found_item_table.php +++ b/templates/found_item_table.php @@ -55,7 +55,7 @@
- + /" class="btn btn-outline-success" title="match"> +
+ + + + + + + + + + + +