Hi all. I am using the following php code to grab passed data of post request(<input type="hidden" name="copy_list" value="23434,34346,34234">) and write each value in to mysql db but i keep getting the following error:
Quote:
Warning: reset() [function.reset]: Passed variable is not an array or object in
write.php on line 64
pointing at this line:
Quote:
reset($id); // Set array pointer to first array element
and write them to mysql.(Note: number of values posted is not know)
I be happy if some one help me grab these data correctly and write them to mysql.Thanks
// Find out how many items were selected and protect against no selection If (is_array($id)) { $amountselected = count($id); } Else { $amountselected = 0; } echo "Number value passed:"; echo $amountselected; echo "<br>";
reset($id); // Set array pointer to first array element foreach ($id as $addrecid) { // Build SQL Insert query
$insert = "INSERT INTO test ( SELECT * FROM $s WHERE friendID = '$addrecid')";
$_POST['copy_list'] will contain a string with one or more coma separated items. To get that into an array would require using the explode() function.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Thanks that solved the problem but now my insert stoped working after i added another insert before $id = array(); . could you tell me what i am doing wrong. i printed out the insert statment and it shows the write statments!!. The insert2 is working but insert inside foreach loop stoped working after i add insert1!!
I post the full code here. I think problem is with db connection because after i added insert2 the insert1 stoped working and only insert2 working now!!
// Find out how many items were selected and protect against no selection If (is_array($id)) { $amountselected = count($id); } Else { $amountselected = 0; } echo "Number value passed:"; echo $amountselected; echo "<br>";
reset($id); // Set array pointer to first array element foreach ($id as $addrecid) {
// Build SQL Insert query
$insert1 = "INSERT INTO singers ( SELECT * FROM test2 WHERE friendID = '$addrecid')";