You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

received.php 804B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. require_once "sql.php";
  3. if(isset($_GET['sender']))
  4. $sender = $_GET['sender'];
  5. else
  6. $sender = "";
  7. if(isset($_GET['text']))
  8. $text = $_GET['text'];
  9. else
  10. $text = "";
  11. if($sender == "")
  12. error("Empty sender");
  13. $select = $db->prepare("SELECT id FROM gates WHERE address=:address");
  14. if(!$select->execute(array(":address" => $_SERVER['REMOTE_ADDR'])))
  15. error("Unable to retrieve gate details");
  16. if($g = $select->fetch())
  17. {
  18. $insert = $db->prepare("INSERT INTO `received` (`sender`, `text`, `gate`) VALUES (:sender, :text, :gate)");
  19. if(!$insert->execute(array(":sender" => $sender, ":text" => $text, ":gate" => $g['id'])))
  20. error("Failed to update database: ".$insert->errorInfo()[2]);
  21. else
  22. echo json_encode(array("id" => $db->lastInsertId()));
  23. }
  24. else
  25. error("You're not allowed to do this");
  26. ?>