www.webdeveloper.com
Results 1 to 3 of 3

Thread: Split insert textarea value per line and insert each line as one record

Threaded View

  1. #1
    Join Date
    Sep 2013
    Posts
    221

    Split insert textarea value per line and insert each line as one record

    I need to know how to do the following using php coding please

    1.take inserted text from a textarea
    2.split the content per line
    3.Insert each line into the database as its own row with own id number
    Can anyone show me how to do this please?

    THis is what I have tried so Far:

    Below is my form page display_form.php:
    HTML Code:
    <form method="post" action="display_db.php">
    Member ID:
          <input name="mid" type="text" value=""><br/><br/>
    Enter Keywords:
          <input name="keywords" type="text" value=""><br/><br/>
          Enter Your Links :
    <textarea name="links" rows="3" cols="20"></textarea><br/><br/>
    
    
    
    <input type="submit" id="button" value=" Submit "/>
    
    </form>
    And below is my display_db.php:
    PHP Code:
    <?php
    $con
    =mysqli_connect("localhost","root","","test");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }
      
      if(isset(
    $_POST["data"]))
    {
      
    $line_data explode("\n"$_POST["keywords"]);
      foreach(
    $line_data as $key => $value)
    {
      
    $sql "INSERT INTO table (display) VALUE('{$value}')";
     
    mysql_query($sql);
    }
    }
      if (!
    mysqli_query($con,$sql))
      {
      die(
    'Error: ' mysqli_error($con));
      }
    echo 
    "1 record added";

    mysqli_close($con);
    ?>
    Ant kind of help is appreciated.
    Last edited by NogDog; 12-14-2013 at 12:17 PM. Reason: added [php] tags
    strad solutionswww.stradsolutions.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles