Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing array in JQuery Script
    text
    copied!<p>Been working on this dumb problem for two days now. If you can help I would sure appreciate it!</p> <p>So my html goes like this:</p> <pre><code>&lt;a class='selected' option ='2' category='1' price='1750.00'&gt;Round Corners&lt;/a&gt; &lt;a class='selected' option ='3' category='1' price='2200.00'&gt;Chamfer Corners&lt;/a&gt; </code></pre> <p>And then my script is:</p> <pre><code>$('#save').click(function(){ var passOptions = new Array(); var i=0; $('.selected').each(function(){ passOptions[i] = $(this).attr('option'); i++; }); console.log(passOptions); $.ajax({ type: "POST", url: "processsaveconfig.php?configid=&lt;? echo $configid; ?&gt;", data: { passOptionsArray : passOptions }, success: function() { $('#pricediv').html(data); } }); }); </code></pre> <p>My php page goes:</p> <pre><code> $passopts = $_REQUEST['passOptionsArray']; mysql_connect($serverpath, $dbusr, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); mysql_query("DELETE FROM se_config_opt_link WHERE se_config_opt_link.f_config_id = '$configid'"); foreach ($_POST['passOptions'] as $opts){ mysql_query("INSERT INTO se_config_opt_link (f_config_id, f_opt_id) VALUES ('$configid', '$opts')"); }; </code></pre> <p>In Firebug in the Console tab I get: ["1", "4", "7"] But in the Response tab it reads:</p> <p><br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/users/c/companion/public_html/dynamic/builder_app/processsaveconfig.php</b> on line <b>17</b><br /></p> <p>I'm stuck. If you can help I would really be grateful.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload