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 = $_POST['cpu_asset'];
$textarea2Submit = $_POST['cpu_serial'];
$textareaSubmit = str_replace("\r", "",$textareaSubmit); //First of all strip
all the returns \r
$textarea2Submit = str_replace("\r", "",$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
for($i = 0; $i < count($inserts);
$i++){
$check = false;
$check = mysql_query('INSERT INTO
labels (`asset`,`serial`) VALUES (\''.$inserts[$i].'\',
\''.$textarea2Submit[$i].'\')');
if($check === 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
$check = 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, May 18, 2007 11:11 AM
To: Moore, Joshua
Cc: bedul; Bill Bolte; [email protected]
Subject: RE: [PHP-WIN] Textarea and mysql
if the $check returns a "false" it would mean that there was an error
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
be separated with a comma (,).
- > VALUES (\'value1\', \'value2\')
Thirdly :) if you are sure these two texareas are "in sync" you might
wanna try to do the following:
for($i = 0; $i < count($inserts); $i++){
...
'INSERT INTO somewhere (`col1`,`col2`) VALUES (\''.$inserts[$i].'\',
\''.$otherSyncedArrfay[$i].'\')'
...
}
Hope I was clear enough :)
Aleksander
Quoting "Moore, Joshua" <[EMAIL PROTECTED]>:
> 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:[EMAIL PROTECTED]
> Sent: Friday, May 18, 2007 3:02 AM
> To: bedul
> Cc: Bill Bolte; [email protected]
> 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" <[EMAIL PROTECTED]>
>> To: <[email protected]>
>> 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:[EMAIL PROTECTED]
>> Sent: Thursday, May 17, 2007 4:17 PM
>> To: [email protected]
>> 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