Textarea and mysql

Textarea and mysql

am 17.05.2007 23:16:47 von Joshua.Moore

------_=_NextPart_001_01C798C9.46B9D220
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello,

=20

Im currently having a bit of an issue with putting user info from a =
textarea
into mysql db with php. With the textarea I need each new line to be a
separate entry into the db fields. So I guess the end result is making =
the
textarea act like a regular text html form. The reason I am using =
textarea is
because I want a user to paste in a long string of numbers

Ex:

11111111

22222222

33333333

....and so on

=20

And each will end up in the same field just different entries.=20

=20

Does anyone have any idea how I can accomplish this?

=20

Thanks


------_=_NextPart_001_01C798C9.46B9D220--

RE: Textarea and mysql

am 17.05.2007 23:22:15 von Bill Bolte

Split the data on a line break maybe? First thing that comes into my
head...=20

-----Original Message-----
From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]=20
Sent: Thursday, May 17, 2007 4:17 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Textarea and mysql

Hello,

=20

Im currently having a bit of an issue with putting user info from a
textarea
into mysql db with php. With the textarea I need each new line to be a
separate entry into the db fields. So I guess the end result is making
the
textarea act like a regular text html form. The reason I am using
textarea is
because I want a user to paste in a long string of numbers

Ex:

11111111

22222222

33333333

....and so on

=20

And each will end up in the same field just different entries.=20

=20

Does anyone have any idea how I can accomplish this?

=20

Thanks

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Textarea and mysql

am 18.05.2007 08:33:05 von Dale Attree

There is only a line break, if the user hits enter, otherwise the textarea
will just wrap the content.

You can use the following:

$textAreaWidth = 60; //Number of cols specified for textarea

$loops = ceil(strlen($_POST['textarea']) / $textAreaWidth);

for($i = 0; $i < $loops; $i++){
$sp = $i * $textAreaWidth;
$line = substr($_POST['textarea'],$sp,$textAreaWidth);
$sql = 'insert into dbTable (fieldname) values ("'.$line.'")';
Mysql_query($sql) or die(mysql_error());
}

-----Original Message-----
From: Bill Bolte [mailto:billb@hightouchinc.com]
Sent: 17 May 2007 11:22 PM
To: php-windows@lists.php.net
Subject: RE: [PHP-WIN] Textarea and mysql

Split the data on a line break maybe? First thing that comes into my
head...

-----Original Message-----
From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
Sent: Thursday, May 17, 2007 4:17 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Textarea and mysql

Hello,



Im currently having a bit of an issue with putting user info from a
textarea
into mysql db with php. With the textarea I need each new line to be a
separate entry into the db fields. So I guess the end result is making
the
textarea act like a regular text html form. The reason I am using
textarea is
because I want a user to paste in a long string of numbers

Ex:

11111111

22222222

33333333

.....and so on



And each will end up in the same field just different entries.



Does anyone have any idea how I can accomplish this?



Thanks

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






************************************************************ ***********************************
The information contained in this e-mail is confidential and may be subject to legal privilege.
Access to this e-mail by anyone other than the intended recipient is unauthorised.

If you are not the intended recipient you must not use, copy, distribute or disclose the e-mail or any part of its contents or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by e-mail (postmaster@jacklinenterprises.com) or telephone (+27 11 265 4200).
This message is free of all known viruses. It has been screened for viruses by Blockmail.
************************************************************ ***********************************

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Textarea and mysql

am 18.05.2007 11:37:24 von bedul

$temp = str_replace("\n","[break]",$inpText); //inpText is from textArea

and then u enter your temp to the sql..

when you want to split it up.. just use

$temp=explode("[break]",$inp4Sql); //hope i don't give wrong function

==spam?? sory===
----- Original Message -----
From: "Bill Bolte"
To:
Sent: Friday, May 18, 2007 4:22 AM
Subject: RE: [PHP-WIN] Textarea and mysql


Split the data on a line break maybe? First thing that comes into my
head...

-----Original Message-----
From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
Sent: Thursday, May 17, 2007 4:17 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Textarea and mysql

Hello,



Im currently having a bit of an issue with putting user info from a
textarea
into mysql db with php. With the textarea I need each new line to be a
separate entry into the db fields. So I guess the end result is making
the
textarea act like a regular text html form. The reason I am using
textarea is
because I want a user to paste in a long string of numbers

Ex:

11111111

22222222

33333333

....and so on



And each will end up in the same field just different entries.



Does anyone have any idea how I can accomplish this?



Thanks

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Textarea and mysql

am 18.05.2007 12:01:31 von Aleksandar Vojnovic

$textareaSubmit = $_POST['textAreaValue'];
//First of all strip all the returns \r
$textareaSubmit = str_replace("\r", "",$textareaSubmit);
//Explode by new line
$inserts = explode("\n", $textareaSubmit);
//check if its array
if(is_array($inserts)){
//run foreach on array
foreach($inserts AS $insertSQL){
$check = false;
$check = mysql_query('INSERT INTO somewhere (`somecolumn`)
VALUES (\''.$insertSQL.'\')');
if($check === true){
//success
}else{
//failure
//do something?
}
}
}

bedul wrote:
> $temp = str_replace("\n","[break]",$inpText); //inpText is from textArea
>
> and then u enter your temp to the sql..
>
> when you want to split it up.. just use
>
> $temp=explode("[break]",$inp4Sql); //hope i don't give wrong function
>
> ==spam?? sory===
> ----- Original Message -----
> From: "Bill Bolte"
> To:
> Sent: Friday, May 18, 2007 4:22 AM
> Subject: RE: [PHP-WIN] Textarea and mysql
>
>
> Split the data on a line break maybe? First thing that comes into my
> head...
>
> -----Original Message-----
> From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
> Sent: Thursday, May 17, 2007 4:17 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Textarea and mysql
>
> Hello,
>
>
>
> Im currently having a bit of an issue with putting user info from a
> textarea
> into mysql db with php. With the textarea I need each new line to be a
> separate entry into the db fields. So I guess the end result is making
> the
> textarea act like a regular text html form. The reason I am using
> textarea is
> because I want a user to paste in a long string of numbers
>
> Ex:
>
> 11111111
>
> 22222222
>
> 33333333
>
> ...and so on
>
>
>
> And each will end up in the same field just different entries.
>
>
>
> Does anyone have any idea how I can accomplish this?
>
>
>
> Thanks
>
>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Textarea and mysql

am 18.05.2007 18:52:04 von Joshua.Moore

I have two textareas that I need to insert into 2 different fields, so =
with
the following code im having trouble getting it to work:

Original:
$textareaSubmit =3D $_POST['textAreaValue'];
//First of all strip all the returns \r
$textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
//Explode by new line
$inserts =3D explode("\n", $textareaSubmit);
//check if its array
if(is_array($inserts)){
//run foreach on array
foreach($inserts AS $insertSQL){
$check =3D false;
$check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)=20
VALUES (\''.$insertSQL.'\')');
if($check ===3D true){
//success
}else{
//failure
//do something?
}
}
}

Mine:

$textareaSubmit =3D $_POST['cpu_asset'];
$textarea2Submit =3D $_POST['cpu_serial'];
$textareaSubmit =3D str_replace("\r", =
"",$textareaSubmit,$textarea2Submit);
//First of all strip all the returns \r
$inserts =3D explode("\n", $textareaSubmit, $textarea2Submit); =
//Explode by
new line
if(is_array($inserts)){ //check if its array
//run foreach on array
foreach($inserts AS $insertSQL){
$check =3D false;
$check =3D mysql_query('INSERT INTO labels (`asset, serial`) VALUES
(\''.$insertSQL.'\')');
if($check ===3D true){
echo "Done";
}else{
echo "An error occured during printing. \n Reason:\n Failed to insert
data into mysql";
}
}
}

Mine doesn't work and im not sure why....

Thanks for your help!

-----Original Message-----
From: Aleksandar Vojnovic [mailto:muadib@consoriana.com]=20
Sent: Friday, May 18, 2007 3:02 AM
To: bedul
Cc: Bill Bolte; php-windows@lists.php.net
Subject: Re: [PHP-WIN] Textarea and mysql


$textareaSubmit =3D $_POST['textAreaValue'];
//First of all strip all the returns \r
$textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
//Explode by new line
$inserts =3D explode("\n", $textareaSubmit);
//check if its array
if(is_array($inserts)){
//run foreach on array
foreach($inserts AS $insertSQL){
$check =3D false;
$check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)=20
VALUES (\''.$insertSQL.'\')');
if($check ===3D true){
//success
}else{
//failure
//do something?
}
}
}

bedul wrote:
> $temp =3D str_replace("\n","[break]",$inpText); //inpText is from =
textArea
>
> and then u enter your temp to the sql..
>
> when you want to split it up.. just use
>
> $temp=3Dexplode("[break]",$inp4Sql); //hope i don't give wrong =
function
>
> ==spam?? sory===3D
> ----- Original Message -----=20
> From: "Bill Bolte"
> To:
> Sent: Friday, May 18, 2007 4:22 AM
> Subject: RE: [PHP-WIN] Textarea and mysql
>
>
> Split the data on a line break maybe? First thing that comes into my
> head...=20
>
> -----Original Message-----
> From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]=20
> Sent: Thursday, May 17, 2007 4:17 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Textarea and mysql
>
> Hello,
>
> =20
>
> Im currently having a bit of an issue with putting user info from a
> textarea
> into mysql db with php. With the textarea I need each new line to be a
> separate entry into the db fields. So I guess the end result is making
> the
> textarea act like a regular text html form. The reason I am using
> textarea is
> because I want a user to paste in a long string of numbers
>
> Ex:
>
> 11111111
>
> 22222222
>
> 33333333
>
> ...and so on
>
> =20
>
> And each will end up in the same field just different entries.=20
>
> =20
>
> Does anyone have any idea how I can accomplish this?
>
> =20
>
> Thanks
>
> =20

--=20
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Textarea and mysql

am 18.05.2007 20:10:52 von muadib

if the $check returns a "false" it would mean that there was an error =20
in your SQL statement. The error might be here:

- > (`asset, serial`)

I doubt you have a column named `asset, serial`

Secondly if you are inserting two values into the SQL then they must =20
be separated with a comma (,).

- > VALUES (\'value1\', \'value2\')

Thirdly :) if you are sure these two texareas are "in sync" you might =20
wanna try to do the following:

for($i =3D 0; $i < count($inserts); $i++){
....
'INSERT INTO somewhere (`col1`,`col2`) VALUES (\''.$inserts[$i].'\', =20
\''.$otherSyncedArrfay[$i].'\')'
....
}

Hope I was clear enough :)

Aleksander

Quoting "Moore, Joshua" :

> I have two textareas that I need to insert into 2 different fields, so wit=
h
> the following code im having trouble getting it to work:
>
> Original:
> $textareaSubmit =3D $_POST['textAreaValue'];
> //First of all strip all the returns \r
> $textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
> //Explode by new line
> $inserts =3D explode("\n", $textareaSubmit);
> //check if its array
> if(is_array($inserts)){
> //run foreach on array
> foreach($inserts AS $insertSQL){
> $check =3D false;
> $check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)
> VALUES (\''.$insertSQL.'\')');
> if($check ===3D true){
> //success
> }else{
> //failure
> //do something?
> }
> }
> }
>
> Mine:
>
> $textareaSubmit =3D $_POST['cpu_asset'];
> $textarea2Submit =3D $_POST['cpu_serial'];
> $textareaSubmit =3D str_replace("\r", "",$textareaSubmit,$textarea2Submit)=
;
> //First of all strip all the returns \r
> $inserts =3D explode("\n", $textareaSubmit, $textarea2Submit); //Explode =
by
> new line
> if(is_array($inserts)){ //check if its array
> //run foreach on array
> foreach($inserts AS $insertSQL){
> =09$check =3D false;
> =09$check =3D mysql_query('INSERT INTO labels (`asset, serial`) VALUES
> (\''.$insertSQL.'\')');
> =09if($check ===3D true){
> =09echo "Done";
> =09}else{
> =09echo "An error occured during printing. \n Reason:\n Failed to insert
> data into mysql";
> }
> }
> }
>
> Mine doesn't work and im not sure why....
>
> Thanks for your help!
>
> -----Original Message-----
> From: Aleksandar Vojnovic [mailto:muadib@consoriana.com]
> Sent: Friday, May 18, 2007 3:02 AM
> To: bedul
> Cc: Bill Bolte; php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Textarea and mysql
>
>
> $textareaSubmit =3D $_POST['textAreaValue'];
> //First of all strip all the returns \r
> $textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
> //Explode by new line
> $inserts =3D explode("\n", $textareaSubmit);
> //check if its array
> if(is_array($inserts)){
> //run foreach on array
> foreach($inserts AS $insertSQL){
> $check =3D false;
> $check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)
> VALUES (\''.$insertSQL.'\')');
> if($check ===3D true){
> //success
> }else{
> //failure
> //do something?
> }
> }
> }
>
> bedul wrote:
>> $temp =3D str_replace("\n","[break]",$inpText); //inpText is from textAre=
a
>>
>> and then u enter your temp to the sql..
>>
>> when you want to split it up.. just use
>>
>> $temp=3Dexplode("[break]",$inp4Sql); //hope i don't give wrong function
>>
>> ==spam?? sory===3D
>> ----- Original Message -----
>> From: "Bill Bolte"
>> To:
>> Sent: Friday, May 18, 2007 4:22 AM
>> Subject: RE: [PHP-WIN] Textarea and mysql
>>
>>
>> Split the data on a line break maybe? First thing that comes into my
>> head...
>>
>> -----Original Message-----
>> From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
>> Sent: Thursday, May 17, 2007 4:17 PM
>> To: php-windows@lists.php.net
>> Subject: [PHP-WIN] Textarea and mysql
>>
>> Hello,
>>
>>
>>
>> Im currently having a bit of an issue with putting user info from a
>> textarea
>> into mysql db with php. With the textarea I need each new line to be a
>> separate entry into the db fields. So I guess the end result is making
>> the
>> textarea act like a regular text html form. The reason I am using
>> textarea is
>> because I want a user to paste in a long string of numbers
>>
>> Ex:
>>
>> 11111111
>>
>> 22222222
>>
>> 33333333
>>
>> ...and so on
>>
>>
>>
>> And each will end up in the same field just different entries.
>>
>>
>>
>> Does anyone have any idea how I can accomplish this?
>>
>>
>>
>> Thanks
>>
>>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Textarea and mysql

am 18.05.2007 22:28:44 von Joshua.Moore

Please forgive me im still new to programming and php. So this is what I =
got
from what you said however I guess I managed to screw the whole code up
because it doesn't work at all anymore :(

$textareaSubmit =3D $_POST['cpu_asset'];
$textarea2Submit =3D $_POST['cpu_serial'];
$textareaSubmit =3D str_replace("\r", "",$textareaSubmit); //First of =
all strip
all the returns \r
$textarea2Submit =3D str_replace("\r", "",$textarea2Submit); //First of =
all
strip all the returns \r
$inserts =3D explode("\n", $textareaSubmit, $textarea2Submit); =
//Explode by
new line
if(is_array($inserts)){ //check if its array
//run foreach on array
for($i =3D 0; $i < count($inserts);
$i++){
$check =3D false;
$check =3D mysql_query('INSERT INTO
labels (`asset`,`serial`) VALUES (\''.$inserts[$i].'\',
\''.$textarea2Submit[$i].'\')');
if($check ===3D true){
echo "Done";
}else{
echo "An error occured during printing. \n Reason:\n Failed
to insert data into mysql";
}
}
}

Im sure one of the problem area(s) is=20

$check =3D mysql_query('INSERT INTO labels (`asset`,`serial`) VALUES
(\''.$inserts[$i].'\', \''.$textarea2Submit[$i].'\')');

However im not sure what the variable $textarea2Submit[$i] is supposted =
to
be. Do I need to create a whole other if(is_array($inserts)){ ??

Thanks for your help


-----Original Message-----
From: muadib@artrebel9.com [mailto:muadib@artrebel9.com]=20
Sent: Friday, May 18, 2007 11:11 AM
To: Moore, Joshua
Cc: bedul; Bill Bolte; php-windows@lists.php.net
Subject: RE: [PHP-WIN] Textarea and mysql

if the $check returns a "false" it would mean that there was an error =20
in your SQL statement. The error might be here:

- > (`asset, serial`)

I doubt you have a column named `asset, serial`

Secondly if you are inserting two values into the SQL then they must =20
be separated with a comma (,).

- > VALUES (\'value1\', \'value2\')

Thirdly :) if you are sure these two texareas are "in sync" you might =20
wanna try to do the following:

for($i =3D 0; $i < count($inserts); $i++){
....
'INSERT INTO somewhere (`col1`,`col2`) VALUES (\''.$inserts[$i].'\', =20
\''.$otherSyncedArrfay[$i].'\')'
....
}

Hope I was clear enough :)

Aleksander

Quoting "Moore, Joshua" :

> I have two textareas that I need to insert into 2 different fields, so =
with
> the following code im having trouble getting it to work:
>
> Original:
> $textareaSubmit =3D $_POST['textAreaValue'];
> //First of all strip all the returns \r
> $textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
> //Explode by new line
> $inserts =3D explode("\n", $textareaSubmit);
> //check if its array
> if(is_array($inserts)){
> //run foreach on array
> foreach($inserts AS $insertSQL){
> $check =3D false;
> $check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)
> VALUES (\''.$insertSQL.'\')');
> if($check ===3D true){
> //success
> }else{
> //failure
> //do something?
> }
> }
> }
>
> Mine:
>
> $textareaSubmit =3D $_POST['cpu_asset'];
> $textarea2Submit =3D $_POST['cpu_serial'];
> $textareaSubmit =3D str_replace("\r", =
"",$textareaSubmit,$textarea2Submit);
> //First of all strip all the returns \r
> $inserts =3D explode("\n", $textareaSubmit, $textarea2Submit); =
//Explode by
> new line
> if(is_array($inserts)){ //check if its array
> //run foreach on array
> foreach($inserts AS $insertSQL){
> $check =3D false;
> $check =3D mysql_query('INSERT INTO labels (`asset, serial`) VALUES
> (\''.$insertSQL.'\')');
> if($check ===3D true){
> echo "Done";
> }else{
> echo "An error occured during printing. \n Reason:\n Failed to insert
> data into mysql";
> }
> }
> }
>
> Mine doesn't work and im not sure why....
>
> Thanks for your help!
>
> -----Original Message-----
> From: Aleksandar Vojnovic [mailto:muadib@consoriana.com]
> Sent: Friday, May 18, 2007 3:02 AM
> To: bedul
> Cc: Bill Bolte; php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Textarea and mysql
>
>
> $textareaSubmit =3D $_POST['textAreaValue'];
> //First of all strip all the returns \r
> $textareaSubmit =3D str_replace("\r", "",$textareaSubmit);
> //Explode by new line
> $inserts =3D explode("\n", $textareaSubmit);
> //check if its array
> if(is_array($inserts)){
> //run foreach on array
> foreach($inserts AS $insertSQL){
> $check =3D false;
> $check =3D mysql_query('INSERT INTO somewhere (`somecolumn`)
> VALUES (\''.$insertSQL.'\')');
> if($check ===3D true){
> //success
> }else{
> //failure
> //do something?
> }
> }
> }
>
> bedul wrote:
>> $temp =3D str_replace("\n","[break]",$inpText); //inpText is from =
textArea
>>
>> and then u enter your temp to the sql..
>>
>> when you want to split it up.. just use
>>
>> $temp=3Dexplode("[break]",$inp4Sql); //hope i don't give wrong =
function
>>
>> ==spam?? sory===3D
>> ----- Original Message -----
>> From: "Bill Bolte"
>> To:
>> Sent: Friday, May 18, 2007 4:22 AM
>> Subject: RE: [PHP-WIN] Textarea and mysql
>>
>>
>> Split the data on a line break maybe? First thing that comes into my
>> head...
>>
>> -----Original Message-----
>> From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
>> Sent: Thursday, May 17, 2007 4:17 PM
>> To: php-windows@lists.php.net
>> Subject: [PHP-WIN] Textarea and mysql
>>
>> Hello,
>>
>>
>>
>> Im currently having a bit of an issue with putting user info from a
>> textarea
>> into mysql db with php. With the textarea I need each new line to be =
a
>> separate entry into the db fields. So I guess the end result is =
making
>> the
>> textarea act like a regular text html form. The reason I am using
>> textarea is
>> because I want a user to paste in a long string of numbers
>>
>> Ex:
>>
>> 11111111
>>
>> 22222222
>>
>> 33333333
>>
>> ...and so on
>>
>>
>>
>> And each will end up in the same field just different entries.
>>
>>
>>
>> Does anyone have any idea how I can accomplish this?
>>
>>
>>
>> Thanks
>>
>>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Textarea and mysql

am 21.05.2007 10:24:02 von luis.moreira

Hi

First, let me just say that "it does not work" is too vague.
You should always describe the problem a little more.

Anyway, there are a couple of things I don't understand on your
script :

$textareaSubmit = str_replace("\r",
"",$textareaSubmit,$textarea2Submit);
$inserts = explode("\n", $textareaSubmit, $textarea2Submit);

Possibly you want to use the functions in both strings
$textareaSubmit and $textarea2Submit, but I believe (I don't know your
version of PHP) that the syntax is wrong.
The function "str_replace" replaces all occurrences of a string
within a string, not within a set of strings.
The same with "explode".
Check the syntax of both.

Luis


-----Original Message-----
From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
Sent: sexta-feira, 18 de Maio de 2007 17:52
To: muadib@consoriana.com; bedul
Cc: Bill Bolte; php-windows@lists.php.net
Subject: RE: [PHP-WIN] Textarea and mysql

I have two textareas that I need to insert into 2 different fields, so with
the following code im having trouble getting it to work:

Original:
$textareaSubmit = $_POST['textAreaValue'];
//First of all strip all the returns \r
$textareaSubmit = str_replace("\r", "",$textareaSubmit);
//Explode by new line
$inserts = explode("\n", $textareaSubmit);
//check if its array
if(is_array($inserts)){
//run foreach on array
foreach($inserts AS $insertSQL){
$check = false;
$check = mysql_query('INSERT INTO somewhere (`somecolumn`)
VALUES (\''.$insertSQL.'\')');
if($check === true){
//success
}else{
//failure
//do something?
}
}
}

Mine:

$textareaSubmit = $_POST['cpu_asset'];
$textarea2Submit = $_POST['cpu_serial'];
$textareaSubmit = str_replace("\r", "",$textareaSubmit,$textarea2Submit);
//First of all strip all the returns \r
$inserts = explode("\n", $textareaSubmit, $textarea2Submit); //Explode by
new line
if(is_array($inserts)){ //check if its array
//run foreach on array
foreach($inserts AS $insertSQL){
$check = false;
$check = mysql_query('INSERT INTO labels (`asset, serial`) VALUES
(\''.$insertSQL.'\')');
if($check === true){
echo "Done";
}else{
echo "An error occured during printing. \n Reason:\n Failed to
insert
data into mysql";
}
}
}

Mine doesn't work and im not sure why....

Thanks for your help!

-----Original Message-----
From: Aleksandar Vojnovic [mailto:muadib@consoriana.com]
Sent: Friday, May 18, 2007 3:02 AM
To: bedul
Cc: Bill Bolte; php-windows@lists.php.net
Subject: Re: [PHP-WIN] Textarea and mysql


$textareaSubmit = $_POST['textAreaValue'];
//First of all strip all the returns \r
$textareaSubmit = str_replace("\r", "",$textareaSubmit);
//Explode by new line
$inserts = explode("\n", $textareaSubmit);
//check if its array
if(is_array($inserts)){
//run foreach on array
foreach($inserts AS $insertSQL){
$check = false;
$check = mysql_query('INSERT INTO somewhere (`somecolumn`)
VALUES (\''.$insertSQL.'\')');
if($check === true){
//success
}else{
//failure
//do something?
}
}
}

bedul wrote:
> $temp = str_replace("\n","[break]",$inpText); //inpText is from textArea
>
> and then u enter your temp to the sql..
>
> when you want to split it up.. just use
>
> $temp=explode("[break]",$inp4Sql); //hope i don't give wrong function
>
> ==spam?? sory===
> ----- Original Message -----
> From: "Bill Bolte"
> To:
> Sent: Friday, May 18, 2007 4:22 AM
> Subject: RE: [PHP-WIN] Textarea and mysql
>
>
> Split the data on a line break maybe? First thing that comes into my
> head...
>
> -----Original Message-----
> From: Moore, Joshua [mailto:Joshua.Moore@tusd1.org]
> Sent: Thursday, May 17, 2007 4:17 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Textarea and mysql
>
> Hello,
>
>
>
> Im currently having a bit of an issue with putting user info from a
> textarea
> into mysql db with php. With the textarea I need each new line to be a
> separate entry into the db fields. So I guess the end result is making
> the
> textarea act like a regular text html form. The reason I am using
> textarea is
> because I want a user to paste in a long string of numbers
>
> Ex:
>
> 11111111
>
> 22222222
>
> 33333333
>
> ...and so on
>
>
>
> And each will end up in the same field just different entries.
>
>
>
> Does anyone have any idea how I can accomplish this?
>
>
>
> Thanks
>
>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php