RE: [PHP-WIN] Textarea and mysql

From: Date: Fri, 18 May 2007 18:10:52 +0000
Subject: RE: [PHP-WIN] Textarea and mysql
References: 1 2 3 4 5  Groups: php.windows 
Request: Send a blank email to php-windows+get-27914@lists.php.net to get a copy of this message
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" <Joshua.Moore@tusd1.org>:
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" <billb@hightouchinc.com> To: <php-windows@lists.php.net> 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


« previous php.windows (#27914) next »