Jump to content

[SOLVED] error: foreach( even after trying $_POST in unchecked checkboxes


phoenixx5

Recommended Posts

When a user searches my site the result may return 100 results or 1000 results.  I've assigned a value $leadid[] to each checkbox.  If a user doesn't want that result saved in their cart, then they simply uncheck the checkbox (which is checked by default).

 

The problem exists when they click to add their list to the cart, i get an error:

Warning: Invalid argument supplied for foreach()

 

I've tried using the following code before the mysql insert but it only inserts the name of the variable as well as the other variables passed in the form.

foreach ($_POST as $leadid => $leadid ){

 

any thoughts?  I've been at it for 6 hours and the Red Bull is fading fast!

Well, that's odd.... it is working, but now it's inserting the values twice... looping once.  hmmmm.

 

here's the code

 

<?
$insertionpoint = (1);
$mysql_host = "";
$mysql_user = "";
$mysql_password = "";
$mysql_dbname = "";

$mysql_access = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die("<font face='Verdana' size='2' color='#FF0099'>Error Code 001: </font><font face='Verdana' size='2' color='#3300CC'>Unable to connect to verify one of the following<ul><li>Hostname of Database</li><li>Username</li><li>Password</li></ul>.</font>");

mysql_select_db($mysql_dbname, $mysql_access) or die("<font face='Verdana' size='2' color='#FF0099'>Error Code 002: </font><font face='Verdana' size='2' color='#3300CC'>Unable to connect to " . $thumbs_dbname . " in the database.</font>");
$insertionpoint = ($insertionpoint+1);

// The form submitted includes a count of the selected checkboxes ($checkboxcount)... we'll use that as the maximum number of times
// that the insert command should be used to insert the proper number of records.
while ($insertionpoint < ($leadstotal+1)){

foreach ($_POST['leadid'] as $key => $leadid ){

$result = mysql_query("INSERT INTO userexports VALUES ('$userexport_id','$login','$userexport_exporttype','$leadid','$userexport_status','$userexport_doy','$userexport_epoch','$userexport_isostamp','$userexport_extra1','$userexport_extra2')", $mysql_access) or die("<font face='Verdana' size='2' color='#FF0099'>Error Code 003: </font><font face='Verdana' size='2' color='#3300CC'>Unable to connect to the table." . mysql_error() . "</font>");
$insertionpoint = ($insertionpoint+1);
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.