<?php require_once 'config.php'; require_once 'inc/respond.php'; $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // connect to the DB $respond = new Respond(); // Send out JSON responses $table = 'fv_data'; if ($db->connect_errno) { $respond->fail("Failed to connect to MySQL: " . $db->connect_error); } // All setup - let's get started with handling any data. $res = $db->query("SELECT *,DATE_FORMAT(dob,'%D %M %Y') as dob_formatted FROM {$table} ORDER BY id DESC"); while ($row = $res->fetch_assoc()) { $data['results'][] = $row; } $respond->success("results", $data);
} } // If we made it this far, the data is generally okay // so let's prepare and submit. $stmt = $db->prepare("INSERT INTO {$table} \n\t(firstname, lastname, email, phone, gender, dob, comments)\n\tVALUES (?,?,?,?,?,?,?)"); $stmt->bind_param('sssssss', $firstname, $lastname, $email, $phone, $gender, $dob, $comments); $stmt->execute(); if ($stmt->error) { $respond->fail('Database Error', $stmt); } else { /* // This is just an example of how the form could send a thank you email, or an email to an administrator // Without some sort of throttling and verification it could totally be used to spam people, it's just a proof of concept though! // If it was real there should probably be some sort of "I am not a robot" captcha on the front end. $mail->addAddress('*****@*****.**', 'FV Form'); // Add a recipient $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Submission Received'; $mail->Body = 'New Submission received...here are the results etc etc'; if(!$mail->send()) { // echo 'Message could not be sent.'; // echo 'Mailer Error: ' . $mail->ErrorInfo; } */ // Send a Success message via JSON $respond->success("updated", $stmt); } $stmt->close();