I have a simple enquiry form which when submitted, I want to post into my database.
// The form (about.tpl)<form action="" method="POST" name="enquiry_form"><label for="fname">First Name*</label><input type="text" id="fname" name="firstname" placeholder="Your name..." style="width: 100%;"required><label for="lname">Last Name*</label><input type="text" id="lname" name="lastname" placeholder="Your last name..." required><label for="phonenumber">Phone Number*</label><input type="text" id="phonenumber" name="phonenumber" placeholder="The best number to contact you on..." required><label for="subject"><br>Any additional information or questions?</label><textarea id="subject" name="subject" placeholder="Write something..."></textarea><p>Please check that all fields have been filled in, otherwise your enquiry will not be properly submitted.</p><br><button type="submit">Submit</button></form>
// about.php<?php
if(isset($_POST['enquiry_form'])) {
$Enquiries = new Enquiries($Conn);
$enquiry_info = $Enquiries -> createEnquiry($_POST['enquiry_form']);
}
// Enquiries class<?php
class Enquiries {
protected $Conn;
public function __construct($Conn){
$this->Conn = $Conn;
}
public function createEnquiry($enquiry_data){
$query = "INSERT INTO enquiries (First_name, Surname, Phone_Number, Additional_query) VALUES (:First_name, :Surname, :Phone_Number, :Additional_query)";
$stmt = $this->Conn->prepare($query);
return $stmt->execute(array('First_name' => $enquiry_data['firstname'],'Surname' => $enquiry_data['lastname'],'Phone_Number' => $enquiry_data['phonenumber'],'Additional_query' => $enquiry_data['subject']
));
}
}
I replaced lines the array at the bottom with static data and it posted them into the database, however, it isn't posting any data when I state the inputs from the form. Any ideas where I'm going wrong?