add ajax to lost form
This commit is contained in:
parent
f949d07115
commit
df470b370f
4 changed files with 93 additions and 25 deletions
54
ajax.php
54
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));
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue