PDA

Click to See Complete Forum and Search --> : Help grabbing multiple post value data


tony007
Jun 30th, 2008, 11:13 AM
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:

Warning: reset() [function.reset]: Passed variable is not an array or object in
write.php on line 64

pointing at this line:

reset($id); // Set array pointer to first array element


I am trying to write 23434,34346,34234 from :
<input type="hidden" name="copy_list" value="23434,34346,34234">

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




$id = array();
$amountselected = 0;
$id = $_POST['copy_list'];

echo "$id";

if(!$id == 0)
{

// 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')";

echo $insert;
//echo $addrecid;
//echo "<br>";
$addsuccess = mysql_db_query ($dbname, $insert);
If ($addsuccess) {

$howmanynew++;
}
}

If ($amountselected == $howmanynew)
{
?>
<div class="confirmBox">
The selected videos have been copied.
</div>
<?
}

}

<form action="./write.php" method=post >

<input name="go" type="hidden" value="yes">
<input type="hidden" name="copy_list" value="23434,34346,34234">
<tr>
<td width="20%">PlayLists Name:
</td>
<td width="50%"><input type="text" name="ListName" size="20"> Max 100 Character</td>
</tr>
<tr>
<td colspan=2>
<p align="center"><input type="submit" value="Create This PlayList" name="B1">
</td>
</tr>
</form>

dclamp
Jun 30th, 2008, 01:44 PM
have you tried using the explode() (http://us3.php.net/explode) function?