Need php help

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0
I need each line from a textarea to be inserted into the db
Each line a seperate piece of data

^problem, no one has been able to solve it so far, I have had multiple devs dm me.
 
Banned forever. Reason: Rules violations

Zyger

Middleman
Supreme
Feedback score
414
Posts
2,209
Reactions
2,615
Resources
0
I need each line from a textarea to be inserted into the db
Each line a seperate piece of data

^problem, no one has been able to solve it so far, I have had multiple devs dm me.
Are the lines properly split using enter, or just moved over to the next line because of a word wrap?
 

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0
When finished with typing a line, is enter pressed to move it to the next line, or are you relying on it automatically moving the text over to the next line when it reaches the side of the box?
Oh I am pasting mc accounts in the textarea so its automatically like that basically.
 
Banned forever. Reason: Rules violations

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0
Then use preg_split to split it into an array, and then insert the lines into the database

Example:
Code:
$str = $_POST['textarea'];
print_r(preg_split('/\r\n|[\r\n]/', $str));
So what value would I exactly be inserting?
 
Banned forever. Reason: Rules violations

Zyger

Middleman
Supreme
Feedback score
414
Posts
2,209
Reactions
2,615
Resources
0
$sql = "INSERT INTO test (test)
VALUES ('$str)";

So that?
Thought you were meaning posting the textarea data, didn't realize you didn't know how to read the code.
You'd need to loop over each line and insert it into the database.
There's better ways to do it, but it'd probably get too complicated.
 

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0
Thought you were meaning posting the textarea data, didn't realize you didn't know how to read the code.
You'd need to loop over each line and insert it into the database.
There's better ways to do it, but it'd probably get too complicated.
How would I go about looping each line, sorry. Very very new to php
 
Banned forever. Reason: Rules violations

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0
Why are you trying to make a website without learning basic PHP?
I haven't seen getting input from a textarea and inserting each line separately in any basic php tutorials :(
 
Banned forever. Reason: Rules violations

Zyger

Middleman
Supreme
Feedback score
414
Posts
2,209
Reactions
2,615
Resources
0
I haven't seen getting input from a textarea and inserting each line separately in any basic php tutorials :(
This is the array you need to loop over
Code:
$arr = preg_split('/\r\n|[\r\n]/', $str)
[DOUBLEPOST=1536656200][/DOUBLEPOST]Also read these:
- https://stackoverflow.com/questions/8834186/php-split-the-content-of-text-area-and-insert-into-mysql
- https://stackoverflow.com/questions/28907537/get-the-lines-from-textarea-and-insert-to-mysql
- https://wordpress.stackexchange.com...d-echo-each-line-separately-wrapped-with-html
 
Last edited:

Isource

Design
Banned
Feedback score
11
Posts
515
Reactions
301
Resources
0

I have been looking at the links you send and I am confused as to why this is not working:

Code:
$input = $_POST['accs'];

$arr = explode("\n", $input);
foreach ($arr as $arr1) {
    $sql = "INSERT INTO accs (account)
    VALUES ($arr1)";
 
Banned forever. Reason: Rules violations
Status
This thread has been locked.
Top