title: How to insert form data to mysql using PHP
body: <p>I've really straight forward question about inserting a record, for some reason when I try to insert a record it always fails. This is my first php project so hopefully someone will guide me.</p>
  <p>I have this form in a modal:</p>
  <pre><code>          &lt;form id='create_blog_form'&gt;
              &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-6 mb-3&quot;&gt;
                &lt;label for=&quot;create_blogTitle&quot; class=&quot;form-label&quot;&gt;Title&lt;/label&gt;
                &lt;input type=&quot;text&quot; maxlength=&quot;50&quot; required class=&quot;form-control shadow-sm create_blogTitle&quot; name='create_blogTitle' id=&quot;create_blogTitle&quot; aria-describedby=&quot;edit_blogTitle&quot;&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-6 mb-3&quot;&gt;
                &lt;label for=&quot;create_blogDate&quot; class=&quot;form-label&quot;&gt;Date&lt;/label&gt;
                &lt;input type=&quot;date&quot; class=&quot;form-control shadow-sm create_blogDate&quot; name='create_blogDate' id=&quot;create_blogDate&quot; aria-describedby=&quot;create_blogDate&quot;&gt;
              &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;mb-3&quot;&gt;
                &lt;label for=&quot;create_blogContent&quot; class=&quot;form-label&quot;&gt;Content&lt;/label&gt;
                &lt;textarea rows=&quot;12&quot; maxlength=&quot;2000&quot; required class=&quot;form-control shadow-sm create_blogContent&quot; name='create_blogContent' id=&quot;create_blogContent&quot; aria-describedby=&quot;create_blogContent&quot;&gt; &lt;/textarea&gt;
              &lt;/div&gt;
              &lt;button type=&quot;submit&quot; class=&quot;btn btn-official text-white w-100 &quot;&gt;Create&lt;/button&gt;
            &lt;/form&gt;
  </code></pre>
  <p>js to show the modal:</p>
  <pre><code>$(document).on('click','.create_blog_btn',function(){
  $('#createBlog').modal('show');})
  </code></pre>
  <p>And to hide, after blog creation:</p>
  <pre><code>$(&quot;#create_blog_form&quot;).on(&quot;submit&quot;, function (e) {
  var dataString = $(this).serialize();
  $.ajax({
  type: &quot;POST&quot;,
  url: &quot;connection/blogs.php?action=create_blog&quot;,
  data: dataString,
  success: function (response) {
     if(response ==1){
          $('#createBlog').modal('hide');
          alertify.success('Added Successfully!')
          $('.view_blogs_area').empty();
          load_blogs_table();
     }
     else{
          alertify.error('Not Added!') //always shows this error message 
     }
  }
  });
  e.preventDefault();});
  </code></pre>
  <p>finally the connection and insertion where I'm having issue: <strong>(I've two columns values that are static and not entered by the user, <em>lang</em> and <em>status</em>)</strong></p>
  <pre><code>&lt;?php
  include &quot;../../../private/dbconnection.php&quot;;
  
  if(isset($_GET['create_blog'])){
  
      $title =$_POST['create_blogTitle'];
      $content =$_POST['create_blogContent'];
      $date =$_POST['create_blogDate'];
  
      $query = $connection-&gt;prepare(&quot;INSERT INTO blogs(`title`,  `content`, `date`, `lang`, `status`) VALUES(:title, :content, :date, :lang, :status)&quot;);
      $query-&gt;execute([':title'=&gt;$title,':content'=&gt;$content, ':date'=&gt;$date, ':lang'=&gt;'en', ':status'=&gt;'draft']);
  
      if($query){
          $arr[] = array(&quot;request&quot;=&gt;&quot;success&quot;);   
      }else{
          $arr[] = array(&quot;request&quot;=&gt;&quot;failed&quot;); 
      }
  }?&gt;
  </code></pre>
  <p>Thank you.</p>