phoenixx5 Posted April 2, 2007 Share Posted April 2, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/ Share on other sites More sharing options...
rtconner Posted April 2, 2007 Share Posted April 2, 2007 foreach ($_POST['leadid'] as $key => $leadid ){ Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/#findComment-220106 Share on other sites More sharing options...
phoenixx5 Posted April 2, 2007 Author Share Posted April 2, 2007 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/#findComment-220110 Share on other sites More sharing options...
rtconner Posted April 2, 2007 Share Posted April 2, 2007 What does this line of code do? while ($insertionpoint < ($leadstotal+1)){ If you are looping over the $leadid array twice, of course everything is going to get inserted twice. Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/#findComment-220112 Share on other sites More sharing options...
phoenixx5 Posted April 2, 2007 Author Share Posted April 2, 2007 THANK YOU!!!!!!!! The insertion point simply added+1 to the amount of times to write to the database. I was duplicating my efforts. MANY THANKS!!!!!!! YOU HAVE SAVED ME FROM PUTTING MY HEAD THROUGH A WALL!!!! Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/#findComment-220118 Share on other sites More sharing options...
rtconner Posted April 2, 2007 Share Posted April 2, 2007 I do accept checks Quote Link to comment https://forums.phpfreaks.com/topic/45334-solved-error-foreach-even-after-trying-_post-in-unchecked-checkboxes/#findComment-220120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.