title: Search function is work but insert function isn't work in php
body: <p>I am self-learn php language. I create the PHP code for the insert to data and search data in databases. I want to insert &amp; search data to the database with MySQL and PHP. I used WAMP server. Finally, the search function is working correctly, but insert function is didn't work. </p>
  
  <p><b>table</b></p>
  
  <p><a href="https://i.stack.imgur.com/AUXMt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AUXMt.jpg" alt="enter image description here"></a></p>
  
  <p>my error in </p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'mysqli_sql_exception' with message '</p>
  </blockquote>
  
  <p>PHP code is:</p>
  
  <pre><code>if(isset($_POST['insert'])){
    $data = getPosts();
    $sql = "INSERT INTO users (id, fname, lname, age) VALUES ('$data[0]','$data[1],'$data[2]','$data[3]')";
  
    $result= mysqli_query($connect,$sql);
  if($result){
      echo 'Insert is success.....'; 
  }
  else{
      echo 'Insert is unsuccess';
  }
  }
  
  function getPosts(){
  
      $posts = array();
      $posts[0] = $_POST['id'];
      $posts[1] = $_POST['fname'];
      $posts[2] = $_POST['lname'];
      $posts[3] = $_POST['age'];
      return $posts;
  }
  
  //Search
  if(isset($_POST['search'])){
      $data = getPosts();
      $search_Query = "SELECT * FROM users WHERE id = $data[0]";
      $search_Result = mysqli_query($connect, $search_Query);
      if($search_Result)
      {
          if(mysqli_num_rows($search_Result))
          {
              while($row = mysqli_fetch_array($search_Result))
              {
                  $id = $row['id'];
                  $fname = $row['fname'];
                  $lname = $row['lname'];
                  $age = $row['age'];
              }
          }
          else{
              echo 'No Data for this id';
          }
      }else{
          echo 'Result Error';
      }
  }
  </code></pre>
  
  <p>html code:</p>
  
  <pre><code> &lt;form action="" method="post"&gt;
    Enter Your Id: &lt;input type="number" name="id" placeholder="Id" value="&lt;?php echo $id;?&gt;"&gt;&lt;br&gt;&lt;br&gt;
    Enter Your First Name: &lt;input type="text" name="fname" placeholder="First Name" value="&lt;?php echo $fname;?&gt;"&gt;&lt;br&gt;&lt;br&gt;
    Enter Your Last Name:&lt;input type="text" name="lname" placeholder="Last Name" value="&lt;?php echo $lname;?&gt;"&gt;&lt;br&gt;&lt;br&gt;
    Enter Your Age:&lt;input type="number" name="age" placeholder="Age" value="&lt;?php echo $age;?&gt;"&gt;&lt;br&gt;&lt;br&gt;
    &lt;div&gt;
     &lt;input type = "submit" name="insert" value="Add"&gt;
     &lt;input type = "submit" name="search" value="Search"&gt;
    &lt;/div&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>Can anyone help me? Thanks any audience.</p>