Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:20:18+00:00 2026-05-26T06:20:18+00:00

I need some help to figure out how to add multiple fields, on a

  • 0

I need some help to figure out how to add multiple fields, on a mysql db, from a textarea with multiple lines. I would like to have each line to be broken into 6 values (one for each field of my db).

for example, I have the following lines:

info1|info2|info3|info4|info5|info6

info1|infob|infoc|infod|infoe|infof

info1|info8|info9|info0|info1|info2

info1|info4|info4|info5|info6|info7

each field is separated with a “|” (thats because of the example I found online, will post here in a few.:)

then I have the following file: insert_form.php

<form action="insert_engine.php" method="post">
  <p>
    <textarea name="pctext" id="pctext" cols="100" rows="10"></textarea>
  </p>
  <p>
    <input type="submit" />
  </p>
</form> 

and I have the insert_engine.php:

<?php
$con = mysql_connect("localhost","USER","PASS");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("DBNAME", $con);

// assuming the text area value is in $_GET["pctext"]
$lines = explode("\n", $_GET["pctext"]);
foreach($lines as $line) {
  list($FIELD1, $FIELD2, $FIELD3, $FIELD4, $FIELD5, $FIELD6) = explode(" | ", $line);
    $sql="INSERT INTO TABLENAME (FIELD1, FIELD2, FIELD3, FIELD4, FIELD5, FIELD6)
      VALUES
      ('$_POST[FIELD1]', '$_POST[FIELD2]', '$_POST[FIELD3]','$_POST[FIELD4]', '$_POST[FIELD5]', '$_POST[FIELD6]')";

    if (!mysql_query($sql,$con))
    {
          die('Error: ' . mysql_error());
    }
    echo "record added";
}
mysql_close($con)
?> 
<meta http-equiv="refresh" content="2;URL=confirmation.php" />

To be really honest I barely know about php, I am learning, by force, looking at examples online, testing then on my Linux, etc. I got this one from another thread from here: Inserting text from textarea into MySQL database without losing formatting and I am trying to put it to work.

I understand that I am connecting to the MySQL, selecting the DB, getting the content from pctext (textarea), exploding each line and breaking by “|” (pipe) and then, using a loop (foreach), inserting into the TABLE.

When I click the submit button on the form, I go to the engine page and after 2 seconds i got to the confirmation page, nothing is inserted on my DB but I do have a empty registry, so something is going on.

Could anyone help me with this script?

thank you in advance

PC

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:20:19+00:00Added an answer on May 26, 2026 at 6:20 am
    $lines = explode("\n", $_GET["pctext"]);
    

    should be

    $lines = explode("\n", $_POST["pctext"]);
    

    Because your form method is set to ‘post’ and not ‘get’

    Also change

    list($FIELD1, $FIELD2, $FIELD3, $FIELD4, $FIELD5, $FIELD6) = explode(" | ", $line);
    

    to

    list($FIELD1, $FIELD2, $FIELD3, $FIELD4, $FIELD5, $FIELD6) = explode("|", $line);
    

    Because your example text doesn’t have spaces around the |

    Also.. list doesn’t turn the elements into $_POST vars

    ('$_POST[FIELD1]', '$_POST[FIELD2]', '$_POST[FIELD3]','$_POST[FIELD4]', '$_POST[FIELD5]', '$_POST[FIELD6]')";
    

    Should be

    (‘$FIELD1’, ‘$FIELD2’, ‘$FIELD3′,’$FIELD4’, ‘$FIELD5’, ‘$FIELD6’)”;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help from the shell-script gurus out there. I have a .txt
Hey all i am in need of some help trying to figure out how
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Trying to figure out datetime module and need some help. I've got a string
I am new to Perl and need some help. In Mysql I have a
still trying to figure out jQuery and I need some help with a sidebar
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help assigning a mouseover event to display some icons that start out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.