title: Php Contact Form Inserting into Mysql
body: <p>LAST EDIT : Everything works now will post below the working code , after clearing up like idealcastle said and fixed some syntax errors everything works as it should together with the javascript validation thank  you everyone</p>
  
  <p>HTML Code here : </p>
  
  <pre><code>&lt;form name = "contact " id="contact_form" action="postcontact.php" method="post" onsubmit="return validateForm();"&gt;
                  &lt;div id ="boxc"&gt;
                      &lt;h3&gt;Porosia juaj ?&lt;/h3&gt;
                      &lt;input name="orders" type="checkbox" value="veshje"&gt;Veshje
                      &lt;input name="orders" type="checkbox" value="mbathje"&gt;Mbathje
                      &lt;input name="orders" type="checkbox" value="stoli"&gt;Stoli
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;label class="required" for="name" &gt;Emri:&lt;/label&gt;&lt;br /&gt;
                      &lt;input id="name" name="name" type="text" value="" size="30" placeholder = "Emri"/&gt;&lt;br /&gt;
                      &lt;span id="name_validation" class="error"&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;label class="required"  &gt;Country/State:&lt;/label&gt;&lt;br /&gt;
                  &lt;div class = "row"id="statecmb"&gt;&lt;select name = "state"&gt;
                       &lt;option value="chose" selected&gt;[choose yours]&lt;/option&gt;
                      &lt;option value="albania"&gt;Albania&lt;/option&gt;
                      &lt;option value="kosovo"&gt;Kosovo&lt;/option&gt;
                      &lt;option value="germany"&gt;Germany&lt;/option&gt;
                      &lt;option value="bangladesh"&gt;Bangladesh&lt;/option&gt;
  
                  &lt;/select&gt;
                  &lt;span id="state_validation" class="error"&gt;&lt;/span&gt;&lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;label class="required" for="email" &gt;Email:&lt;/label&gt;&lt;br /&gt;
                      &lt;input id="email" name="email" type="text" value="" size="30"placeholder = "Email" /&gt;&lt;br /&gt;
                      &lt;span id="email_validation" class="error"&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;label class="required" for="message" &gt;Mesazhi:&lt;/label&gt;&lt;br /&gt;
                      &lt;textarea id="message" name="message" rows="7" cols="30" placeholder = "Mesazhi"&gt;&lt;/textarea&gt;&lt;br /&gt;
                      &lt;span id="message_validation" class="error"&gt;&lt;/span&gt;
                  &lt;/div&gt;
  
                  &lt;input name="submit" id = "sub"type="submit" value="Submit" /&gt;
                  &lt;div class="rating"&gt;
                      &lt;h3&gt;Vlerso Sherbimin :&lt;/h3&gt;
                      &lt;input type="radio" name="rate" value="1"&gt;1
                      &lt;input type="radio" name="rate"value="2"&gt;2
                      &lt;input type="radio" name="rate" value="3"&gt;3
                      &lt;input type="radio"name="rate" value="4"&gt;4
                      &lt;input type="radio" name="rate" value="5"&gt;5
                  &lt;/div&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>Javascript file : </p>
  
  <pre><code>function validateForm() {
      var valid = 1;
      var email = document.getElementById('email');
      var email_validation = document.getElementById("email_validation");
      var name = document.getElementById('name');
      var name_validation = document.getElementById("name_validation");
      var message_validation = document.getElementById("message_validation");
      var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  
      if (name.value === "") {
          valid = 0;
          name_validation.innerHTML = "Ju lutem shenoni emrin tuaj";
          name_validation.style.display = "block";
          name_validation.parentNode.style.backgroundColor = "#FFDFDF";
      } else {
          name_validation.style.display = "none";
          name_validation.parentNode.style.backgroundColor = "transparent";
      }
  
      if (message.value === "") {
          valid = 0;
          message_validation.innerHTML = "Ju lutem plotesoni fushen e mesazhit";
          message_validation.style.display = "block";
          message_validation.parentNode.style.backgroundColor = "#FFDFDF";
      } else {
          message_validation.style.display = "none";
          message_validation.parentNode.style.backgroundColor = "transparent";
      }
  
      if (email.value === "") {
          valid = 0;
          email_validation.innerHTML = "Ju lutem shenoni email tuaj";
          email_validation.style.display = "block";
          email_validation.parentNode.style.backgroundColor = "#FFDFDF";
      } else {
          email_validation.style.display = "none";
          email_validation.parentNode.style.backgroundColor = "transparent";
      }
  
      if (!filter.test(email.value)) {
          valid = 0;
          email_validation.innerHTML = "Email juaj nuk eshte valid";
          email_validation.style.display = "block";
          email_validation.parentNode.style.backgroundColor = "#FFDFDF";
      } else {
          email_validation.style.display = "none";
          email_validation.parentNode.style.backgroundColor = "transparent";
      }
      if (!valid)
          alert("KENI ERROR : Fushat duhen te plotesohen ");
  
  }
  </code></pre>
  
  <p>PHP FIle :</p>
  
  <pre><code>&lt;?php
  $host = 'localhost';
  $user = 'root';
  $pass = '';
  $db = 'herdesigns';
  $con = mysqli_connect($host, $user, $pass,$db) or die(mysqli_error());
  /* mysqli_select_db($con , $db); */
  ?&gt;
  
  &lt;?php
  
  if (isset($_POST['submit']))
  {
  $name = mysqli_real_escape_string($con, $_POST['name']);
  $email = mysqli_real_escape_string($con, $_POST['email']);
  $message = mysqli_real_escape_string($con, $_POST['message']);
  $rate = mysqli_real_escape_string($con, $_POST['rate']);
  $orders = mysqli_real_escape_string($con, $_POST['orders']);
  $state = mysqli_real_escape_string($con, $_POST['state']);
  /*$con = mysqli_connect($host, $user, $pass,$db) or die(mysqli_error());*/
  /*mysqli_select_db($con , $db);*/
  $sql = "INSERT INTO contacts (
  orders,
  name,
  state,
  email,
  message,
  rate
  )
  VALUES (
  '$orders',
  '$name',
  '$state',
  '$email',
  '$message',
  '$rate'
  )";
  if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
  }
  echo "Mesazhi juaj eshte postuar me sukses";
  header('Location:contact.php');
  
  mysqli_query($con, $sql);
  
  mysqli_close($con);
  }
  ?&gt;
  </code></pre>