RE: Textarea and mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx] 
Sent: sexta-feira, 18 de Maio de 2007 17:52
To: muadib@xxxxxxxxxxxxxx; bedul
Cc: Bill Bolte; php-windows@xxxxxxxxxxxxx
Subject: RE:  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@xxxxxxxxxxxxxx] 
Sent: Friday, May 18, 2007 3:02 AM
To: bedul
Cc: Bill Bolte; php-windows@xxxxxxxxxxxxx
Subject: Re:  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" <billb@xxxxxxxxxxxxxxxx>
> To: <php-windows@xxxxxxxxxxxxx>
> Sent: Friday, May 18, 2007 4:22 AM
> Subject: RE:  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@xxxxxxxxx] 
> Sent: Thursday, May 17, 2007 4:17 PM
> To: php-windows@xxxxxxxxxxxxx
> Subject:  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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux