[SOLVED] array input box[]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

[SOLVED] array input box[]

Post 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
Last edited by ol4pr0 on Mon May 30, 2005 4:18 pm, edited 1 time in total.
programmermatt
Forum Commoner
Posts: 65
Joined: Tue Mar 15, 2005 5:03 pm
Contact:

Post by programmermatt »

How about:

Code: Select all

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

update tbl set fieldname=$clean_list where id=1
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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";
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Working like a charm Thanks
Post Reply