sorry to dig up this old thread but im having problems trying to get the data out of the array.
i got this code in the form
<input type=checkbox name=functions[0] value=accounting> Accounting<br>
<input type=checkbox name=functions[1] value="word processing"> Word Processing<br>
<input type=checkbox name=functions[2] value="Sales Aids"> Sales Aids <br>
<input type=checkbox name=functions[3] value="client policy information"> Client Policy Information<br>
<input type=checkbox name=functions[4] value=applications> Applications<br>
<input type=checkbox name=functions[5] value=claims> Claims <br>
<input type=checkbox name=functions[6] value="rate/quote"> Rate/Quote <br>
<input type=checkbox name=functions[7] value=other> Other functions (Be specific)
in the php code i post the data to, i push the post array onto a stack with this.
$count = 0;
foreach ($_POST as $key => $value) { //take name&data pair
array_push($stack, $key, $value);//and put it onto the stack
echo $count.": ".$key." - ".$value."<br>";
$count++;
}
I'm inserting the data into mysql. I'm using the following function to create a insert query.
function insert($x, $stack, $table) {// x equals how many values to pull off the stack, stack is the stack array, and table is a string for which table to insert to
$query = "insert into ".$table." set ";//move data into table
for ($i=0;$i<$x;$i+=2) {//Get data
if (substr(pos($stack), 0, 4) == "com_") // is field name prefixed with com_?
$query = $query.substr_replace(pos($stack),"",0,4)."='";//Get field name shave off com_
else
$query = $query.pos($stack)."='";//Get field name
next($stack); echo "<BR>-".pos($stack)."-<BR>";
if (pos($stack) == "Array") { // Is the data in an array? (checkboxes)
echo "in<BR>"; prev($stack); // get array name
foreach(pos($stack) as $element)
$query = $query.$element.","; // add all set checkboxes as data
$query= $query."',";// finish query statement
next($stack); next($stack); //move to next data pair
} else {
$query= $query.pos($stack)."',";//Get data entry
next($stack); // move to next data pair
}
//echo $i."<br>";
}
$query = substr($query,0,(strlen($query)-1));//shave last comma
return $query;
}
my problem is i can't figure out a way to identify an array and add the field names & values to the query string.
i try to identify the array by using
if (pos($stack) == "Array") { // Is the data in an array? (checkboxes)
but the expression never goes true even though the echo before this statement outputs Array. Also, im almost sure the foreach inside that if statement will not execute as i think it should.