title: How do I submit separate rows in my MySQL Database for every line break I make in a text area form?
body: <p>I'm trying to create a text area form were someone can enter multiple links that are separated by line breaks and each link goes into its own row under the link table in my database. I can't seem to figure it out. I've looked everywhere.</p>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;link rel="stylesheet" type="text/css" href="style.css"&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action="insert.php" method="post"&gt;
              &lt;textarea action="results.php" id="textarea" name="url" class="boxsizingBorder"&gt;
              &lt;/textarea&gt;
              &lt;br /&gt;
              &lt;textarea id="results" name="conversion" class="boxsizingBorder"&gt;&lt;/textarea&gt;&lt;br /&gt;
              &lt;input type="submit" value="Add Records" id="convert" onclick="getTrackData()"&gt;
              &lt;span id="counter"&gt;&lt;/span&gt;
          &lt;/form&gt;
          &lt;script src="script.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>insert.php</strong></p>
  
  <pre><code>&lt;?php
      session_start();
  
      include('db.php');
  
      $query = mysql_query("SELECT * FROM persons");
  
      // Escape user inputs for security
  
      $url = $_POST['url'];
      $array = preg_split('/[\n\r]+/', $url);
  
      // attempt insert query execution
      $sql = "INSERT INTO persons (url) VALUES ('$url')";
      if(mysqli_query($link, $sql)) {
          echo "Records added successfully.";
      } else{
          echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
      }
  
      // close connection
      mysqli_close($link);
  ?&gt;
  </code></pre>
  
  <p><strong>This is how it looks:</strong>
  <a href="http://i.imgur.com/dsxtx6F.png" rel="nofollow">http://i.imgur.com/dsxtx6F.png</a></p>
  
  <p><strong>This is how I want it to look:</strong>
  <a href="http://i.imgur.com/CzwHj5i.png" rel="nofollow">http://i.imgur.com/CzwHj5i.png</a></p>
  
  <p><strong>EDIT:</strong> I made the changes to the mysql API, but still can't seem to figure out how to get each link in its own row.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>&lt;?php
      include('db.php');
  
  
      // Escape user inputs for security
  
      $url = $_POST['url'];
      $array = explode('\n', $url);
  
      // attempt insert query execution
      foreach($array as $url) {
          mysqli_query($con, "INSERT INTO persons (url) VALUES ('$url')");
          // close connection
          mysqli_close($con);
      }
  ?&gt;
  </code></pre>