Jump to content

[SOLVED] Is there any way to separate lines in a textarea into seperate variables?


Recommended Posts

Lets say, for example, I have a textarea, and into that textarea I type the following

Line1

Line2

Line3

Line4

 

Would there be any way to write a script to put each of those lines into a DB row?

The table is called "lines" and the only field is "the_line", apart from the auto increment line_id.

 

In other words, I want PHP to take each line and store it as a DB entry. Another example:

 

This is line 1

This is line 2

 

And I want my scrupt to take that information and store each line in a seperate DB row. How do I separate the lines into variables? and run htmlentities on each of them first?

 

The textarea name is "testing", for reference...

 

I know this is possible, I've done it before but its been a while and I just can;t remember the code, any help would be greatly appreciated!

did you mean like this (does it even work lol.) very bad programming theo.......?

 

<?php

$text="line1 line2 line3 line4 line5";

$a=explode(' ',$text);

foreach($a as $res){

$res=mysql_resl_esacpe_string($_POST['res']);

$sql="INSERT INTO somethink (line1, line2, line3, line4, line5)VALUES('$res')";
$sql_result=mysql_query($sql) or die(mysql_error());
}
?>

  • 5 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.