Skip to content
Browse files

subscribe script

  • Loading branch information...
1 parent 544db3c commit ae028d6b9b2046c523ad72a3dc7ee11ff05b8b85 @vesparny vesparny committed
Showing with 33 additions and 0 deletions.
  1. +33 −0 subscribe.php
View
33 subscribe.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * Form processing logic
+ */
+function process( $string ){
+ $dbhost = 'localhost';
+ $dbname = 'poseidon';
+ $collection = 'subscriptions';
+
+ $conn = new MongoClient("mongodb://$dbhost");
+ $col = $conn->$dbname->$collection;
+
+ $doc = array(
+ 'email' => $string,
+ 'timestamp' => new MongoDate()
+ );
+
+ try{
+ $col->insert($doc);
+ } catch(MongoCursorException $e) {
+ echo "It's all good, we already have that email address in our database.";
+ exit;
+ }
+ echo "Thanks, we will notify you soon with exciting news!";
+}
+
+if(!$_POST){
+ echo "Hey man, you're supposed to be submitting a form!";
+}else{
+ process( $_POST['email'] );
+}
+

0 comments on commit ae028d6

Please sign in to comment.
Something went wrong with that request. Please try again.