1234567891011121314151617181920212223242526272829 |
- <?php
- require_once "sql.php";
- if(isset($_GET['sender']))
- $sender = $_GET['sender'];
- else
- $sender = "";
- if(isset($_GET['text']))
- $text = $_GET['text'];
- else
- $text = "";
-
- if($sender == "")
- error("Empty sender");
-
- $select = $db->prepare("SELECT id FROM gates WHERE address=:address");
- if(!$select->execute(array(":address" => $_SERVER['REMOTE_ADDR'])))
- error("Unable to retrieve gate details");
-
- if($g = $select->fetch())
- {
- $insert = $db->prepare("INSERT INTO `received` (`sender`, `text`, `gate`) VALUES (:sender, :text, :gate)");
- if(!$insert->execute(array(":sender" => $sender, ":text" => $text, ":gate" => $g['id'])))
- error("Failed to update database: ".$insert->errorInfo()[2]);
- else
- echo json_encode(array("id" => $db->lastInsertId()));
- }
- else
- error("You're not allowed to do this");
- ?>
|