title: Sending PHP form to MySQL database
body: <p>I am new to PHP and am really struggling to post my PHP contact form data to my database (MySQL, MAMP, phpMyAdmin), I dont know why I am finding this so complex, I have been looking at my code for ages but can not figure it out. <a href="https://i.stack.imgur.com/wYJsy.png" rel="nofollow noreferrer">my database structure</a></p>
  
  <p>connection.php</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "root";
  $dbname = "FutureDesign";
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  
  // Check connection
  //if ($conn-&gt;connect_error) {
  //    die("Connection failed: " . $conn-&gt;connect_error);
  //} 
  //echo "Connected successfully";
  
  $name = $_POST['name'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  
  $sql = "INSERT INTO ContactForm (name, phone, email, message ) VALUES ('$name', '$phone', '$email', '$message')";
  
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo "New record created successfully";
  } else {
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>contact.php</p>
  
  <pre><code>&lt;form name="sentMessage" id="contactForm" method="post" action="connection.php" novalidate&gt;
              &lt;div class="control-group form-group"&gt;
                &lt;div class="controls"&gt;
                  &lt;label&gt;Full Name:&lt;/label&gt;
                  &lt;input type="text" class="form-control" name="name" id="name" required data-validation-required-message="Please enter your name."&gt;
                  &lt;p class="help-block"&gt;&lt;/p&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="control-group form-group"&gt;
                &lt;div class="controls"&gt;
                  &lt;label&gt;Phone Number:&lt;/label&gt;
                  &lt;input type="tel" class="form-control" name="phone" id="phone" required data-validation-required-message="Please enter your phone number."&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="control-group form-group"&gt;
                &lt;div class="controls"&gt;
                  &lt;label&gt;Email Address:&lt;/label&gt;
                  &lt;input type="email" class="form-control" name="email" id="email" required data-validation-required-message="Please enter your email address."&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="control-group form-group"&gt;
                &lt;div class="controls"&gt;
                  &lt;label&gt;Message:&lt;/label&gt;
                  &lt;textarea rows="10" cols="100" class="form-control" name="message" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"&gt;&lt;/textarea&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div id="success"&gt;&lt;/div&gt;
              &lt;!-- For success/fail messages --&gt;
              &lt;button type="submit" value="submit" class="btn btn-primary" id="sendMessageButton"&gt;Send Message&lt;/button&gt;
            &lt;/form&gt;
  </code></pre>