From a44a0e047a7582fe7e31743e1b03a17cf2987f73 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Thu, 9 Mar 2017 00:28:02 -0500 Subject: Created the ability to post ads, rating framework --- dash/post.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dash/post.php (limited to 'dash/post.php') diff --git a/dash/post.php b/dash/post.php new file mode 100644 index 0000000..6fdd2fd --- /dev/null +++ b/dash/post.php @@ -0,0 +1,67 @@ +'; +require('header.php'); +do { + if (!empty($_POST['post'])) { + $patterns = array( + 'title' => '/^.+$/', + 'category' => '/^\d*$/', + 'description' => '/^.+$/', + 'pay' => '/^(\d+|\d+\.\d+|\.\d+)$/', + 'time' => '/^\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}$/', + 'location' => '/^.+$/', + ); + foreach ($patterns as $pkey => $pattern) { + if (!preg_match($pattern, $_POST[$pkey])) { + $err = 'One or more fields have been omitted. All fields are required in order to post an ad.'; + break; + } + } + $stmt = $db->prepare('INSERT INTO ads (uid, title, cat, pay, time, location, description) VALUES (?, ?, ?, ?, ?, ?, ?)') or dash_fatal($db->error); + $stmt->bind_param('isidiss', $b_user['id'], $_POST['title'], $_POST['cat'], $_POST['pay'], strtotime($_POST['time']), $_POST['location'], $_POST['description']); + $stmt->execute(); + if ($stmt->affected_rows < 1) dash_fatal('Your ad was unable to be posted.'); + dash_fatal('Your ad has been posted.', $b_config['base_url'].'dash/ads.php?id='.$stmt->insert_id); + } +} while (false); +$result = $db->query('SELECT id, cat_name FROM categories') or dash_fatal($db->error); +?> +
+

Post an Ad

+
+
+
+

+

+ +

+

+
+
+
+

Pays $

+

Takes place on...

+

At...

+
+
'.PHP_EOL.'

'.htmlentities($err).'

'.PHP_EOL; +?> +
+

+ + + -- cgit v1.2.3