$prev = $value["id"] - 1; $_SESSION["prev"] = $prev; } } if ($_GET["load"] === "interval") { if ($key === 0) { $next = $value["id"] + 1; $_SESSION["next"] = $next; } } if ($_GET["load"] === "earlier") { if ($key === mysqli_num_rows($result) - 1) { $prev = $value["id"] - 1; $_SESSION["prev"] = $prev; } } } // let's create our response array $response = array(); if (!empty($messages)) { $response["messages"] = $messages; } $response["info"] = array(); if (!empty($next)) { $response["info"]["nextM"] = $next; } if (!empty($prev)) { $response["info"]["prevM"] = $prev; } suicide($response, "success");
if ($_FILES["real_img"]["size"] > 1500000) { suicide("Error: File uploaded exceeds maximum upload size.", "error"); } // getting file extension $extension = pathinfo($_FILES['real_img']['name'])["extension"]; //setting random name, setting directory location (for the original image) $rand = bin2hex(openssl_random_pseudo_bytes(10)); $filename = $rand . "." . $extension; $file_dir = "files/" . $filename; // moving file to the directory if (!move_uploaded_file($_FILES["real_img"]["tmp_name"], $file_dir)) { suicide("Error moving file to the direcotry.", "error"); } $content = $file_dir; } else { $content = $_POST["content"]; } // now let's do the MYSQL query in the parametrized way.. $stmt = mysqli_prepare($db, "INSERT INTO messages (userid, type, content, date) VALUES (?, ?, ?, ?)"); if (!mysqli_stmt_bind_param($stmt, 'isss', $userid, $type, $content, $date)) { suicide("Error: " . mysqli_error($db), "error"); } if (!mysqli_stmt_execute($stmt)) { suicide("Error: " . mysqli_error($db), "error"); } if (!mysqli_stmt_close($stmt)) { suicide("Error: " . mysqli_error($db), "error"); } // aaaannndd let's suicide with success. suicide("posted", "success");