...

View Full Version : Posting Values from Array



thoford75
02-28-2012, 03:41 PM
Hi guys. I have a form which returns an array:

[furn_flag] => Array
(
[0] => something
[1] =>
[2] => something else
)


(note [1] is blank)

How do I insert the values into my database (foreach?) as individual rows?

For example in the above case inserted into a table called Flags would be:

array_id = 0, array_text=something
array_id = 2, array_text=something else

The blank array would not be inserted...

abduraooft
02-28-2012, 04:18 PM
The blank array would not be inserted...
Make use of array_filter() to remove the empty cells.

thoford75
02-28-2012, 05:40 PM
Thanks. I've inserted that into my code which now looks like this:


$furn_array = (array_filter($_POST['furn_flag']));

foreach ($furn_array as $id=>$title)


{

$quote_id = $_POST['quote_id'];
$name = $quote_id . '-' . $id;
$date = gmdate('Y-m-d H:i:s');

$result = mysql_query("UPDATE dbFlags SET edited='$date',title='$title',name='$name'");

if (mysql_affected_rows()==0) {

$result = mysql_query("INSERT INTO dbFlags (edited,title,name) VALUES ('$edited','$title','$name')");

}
}

An example of the returned array would be:
Array ( [1] => First Thing [2] => Second Thing )

The mysql update (or insert) works only for the last array however. What am I missing?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum