title: Filtering out lines in TXT and inserting into database
body: <p>I am trying to search for a string in a line in a txt file, the line that contains the string which I am searching for has to be inserted into my database.</p>
  
  <p>The php while loops through all lines an like I said, I am trying to insert the lines it finds into my Database.</p>
  
  <p>Now the problem is, that if I run this code, it inserts all of the txt file in my database, I can't figure out why.</p>
  
  <pre><code>$search = $_GET["search"]; 
  $logfile = $_GET['logfile'];
  // Read from file 
  $file = fopen($logfile, "r");
  ?&gt; 
  &lt;head&gt; &lt;title&gt;Searching: &lt;?php echo $search ?&gt;&lt;/title&gt; &lt;/head&gt; 
  &lt;?php
  while( ($line =  fgets($file) )!= false)
  {
  if(stristr($line,$search))
  $servername = "localhost";
  $username = "root";
  $password = "pass";
  $dbname = "db";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  if(stristr($line,$search))
  $sql = "INSERT INTO `ingamebanlist` (Ban, Timestamp) VALUES ('$line', '$timestamp')";
  if ($conn-&gt;query($sql) === TRUE) {
  echo "New record created successfully";
  } else {
  echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  $conn-&gt;close();
  // case insensitive
  echo "&lt;font face='Arial'&gt; $line &lt;/font&gt;&lt;hr&gt;";
  }
  fclose($file);
  </code></pre>
  
  <p>Please ask any questions if it is unclear</p>