Page 1 of 1

[SOLVED] array input box[]

Posted: Sun May 29, 2005 5:52 pm
by ol4pr0

Code: Select all

<input type=&quote;textbox&quote; name=&quote;inputї]&quote; />
<input type=&quote;textbox&quote; name=&quote;inputї]&quote; />
<input type=&quote;textbox&quote; name=&quote;inputї]&quote; />
the following will give me a clean list of the input boxes[]
but i cant use it to insert that list into the db, unless i missed some.

Code: Select all

#example
for ($i=0;$i<sizeof($_REQUEST['input']);$i++) $upd_this = $_REQUEST['input'][$i];
update tbl set fieldname=$upd_this where id=1 //this wont work.
Now i could use serialize ofcourse, but i would like to be able to insert a clean list. for example

Code: Select all

#print_r($_REQUEST['input']) outputs array("1"=>"one","2"=>"two","3"=>"three");
$clean_list = "one,two,three";
update tbl set fieldname=$clean_list where id=1
Hope this wasnt all to confusing 8O

Posted: Sun May 29, 2005 6:04 pm
by programmermatt
How about:

Code: Select all

foreach( $_REQUEST['input'] as $v ) {
  $clean_list .= $v.",";
}

update tbl set fieldname=$clean_list where id=1

Posted: Sun May 29, 2005 7:30 pm
by Burrito
just set a var above your loop and then use the concat operator "." to add to the string var and then dump that into your db.

matt had that idea...

Code: Select all

$var = "";
foreach($_POST['textbox'] as $postvar){
$var .= $postvar;
}
$query = "update tbl set fieldname = '".$postvar."' where id = 1";

Posted: Mon May 30, 2005 4:18 pm
by ol4pr0
Working like a charm Thanks