Note that there are some explanatory texts on larger screens.

plurals
  1. PO2d array falls apart in ajax call
    text
    copied!<p>I have a 2D array in JS.</p> <p>I alert the array before I ajax it and the array is intact and all good.</p> <p>When I ajax it, I get an error, so I have now ajax'd the array to a page that just runs a var dump and the array tails off half way through and loses structure and data</p> <p>heres the js</p> <pre><code> $.ajax({ type: "POST", url: "ajax/updateElements.php", data: {outerarray:outerarray}, success: function(data){ alert("data="+data); }, error: function(data){ alert("error"); } }); </code></pre> <p>the php</p> <pre><code> &lt;?php var_dump($_POST['outerarray']); ?&gt; </code></pre> <p>and the returned data</p> <pre><code> data=array(40) { [0]=&gt; array(20) { [0]=&gt; string(2) "47" [1]=&gt; string(2) "46" [2]=&gt; string(2) "-1" [3]=&gt; string(3) "100" [4]=&gt; string(2) "35" [5]=&gt; string(5) "shape" [6]=&gt; string(190) "shape" [7]=&gt; string(1) "0" [8]=&gt; string(1) "0" [9]=&gt; string(5) "solid" [10]=&gt; string(3) "000" [11]=&gt; string(1) "0" [12]=&gt; string(0) "" [13]=&gt; string(1) "1" [14]=&gt; string(2) "st" [15]=&gt; string(3) "206" [16]=&gt; string(2) "54" [17]=&gt; string(1) "0" [18]=&gt; string(1) "1" [19]=&gt; string(1) "F" }...until [12]=&gt; array(20) { [0]=&gt; string(2) "33" [1]=&gt; string(3) "179" [2]=&gt; string(3) "376" [3]=&gt; string(3) "578" [4]=&gt; string(3) "203" [5]=&gt; string(4) "text" [6]=&gt; string(933) "text" [7]=&gt; string(2) "11" [8]=&gt; string(1) "1" [9]=&gt; string(5) "solid" [10]=&gt; string(3) "000" [11]=&gt; string(1) "0" [12]=&gt; string(0) "" [13]=&gt; string(1) "1" [14]=&gt; string(0) "" [15]=&gt; string(3) "206" [16]=&gt; stri </code></pre> <p>and thats where it tails off</p> <p>any clues? I have been banging my head against a wall for a week over this</p> <p>heres the PDO code</p> <pre><code> $arraycount=count($_POST['outerarray']); for($m=0; $m&lt;$arraycount; $m++){ $box_id = $_POST['outerarray'][$m][0]; $top= $_POST['outerarray'][$m][1]; $left = $_POST['outerarray'][$m][2]; $width = $_POST['outerarray'][$m][3]; $height = $_POST['outerarray'][$m][4]; $type = $_POST['outerarray'][$m][5]; $content = str_replace("\n", "&lt;br&gt;",$_POST['outerarray'][$m][6]); $zindex = $_POST['outerarray'][$m][7]; $borderwidth = $_POST['outerarray'][$m][8]; $borderstyle = $_POST['outerarray'][$m][9]; $bordercolor = $_POST['outerarray'][$m][10]; $padding = $_POST['outerarray'][$m][11]; $weblink = $_POST['outerarray'][$m][12]; $opacity = $_POST['outerarray'][$m][13]; $shapetype = $_POST['outerarray'][$m][14]; $page_ref = $_POST['outerarray'][$m][15]; $site_ref = $_POST['outerarray'][$m][16]; $deletedelement = $_POST['outerarray'][$m][17]; $allpages = $_POST['outerarray'][$m][18]; $pageSection = $_POST['outerarray'][$m][19]; $stmt = $db-&gt;prepare("SELECT * FROM site_content WHERE site_ref=:site_ref AND page_ref=:page_ref AND box_id=:box_id"); $stmt-&gt;execute(array(':site_ref' =&gt; $site_ref, ':page_ref' =&gt; $page_ref, ':box_id' =&gt; $box_id)); $row_count = $stmt-&gt;rowCount(); if($row_count==0){ $stmt = $db-&gt;prepare("INSERT INTO site_content(page_ref, site_ref, box_type, box_id, box_top, box_left, box_width, box_height, content, weblink , zindex, border_width, border_colour, border_style, padding, image_opacity, shapetype, allPages, pageSection) VALUES(:field1,:field2,:field3,:field4,:field5,:field6,:field7,:field8,:field9,:field10,:field11,:field12,:field13,:field14,:field15,:field16,:field17,:field18,:field19)"); $stmt-&gt;execute(array(':field1' =&gt; $page_ref, ':field2' =&gt; $site_ref, ':field3' =&gt; $type, ':field4' =&gt; $box_id, ':field5' =&gt; $top, ':field6' =&gt; $left, ':field7' =&gt; $width, ':field8' =&gt; $height, ':field9' =&gt; $content, ':field10' =&gt; $weblink, ':field11' =&gt; $zindex, ':field12' =&gt; $borderwidth, ':field13' =&gt; $bordercolor, ':field14' =&gt; $borderstyle, ':field15' =&gt; $padding, ':field16' =&gt; $opacity, ':field17' =&gt; $shapetype, ':field18' =&gt; $allpages, ':field19' =&gt; $pageSection)); $affected_rows = $stmt-&gt;rowCount(); if($affected_rows !=0){ echo "&lt;br&gt;content added succesfully"; }else{ echo "&lt;br&gt;no content added"; } }else{ if($deletedelement=="1"){ $stmt = $db-&gt;prepare("DELETE FROM site_content WHERE site_ref=:site_ref AND page_ref=:page_ref AND box_id=:box_id"); $stmt-&gt;execute(array(':site_ref' =&gt; $site_ref, ':page_ref' =&gt; $page_ref, ':box_id' =&gt; $box_id)); $stmt-&gt;execute(); $affected_rows = $stmt-&gt;rowCount(); if($affected_rows !=0){ echo "&lt;br&gt;content deleted succesfully"; }else{ echo "&lt;br&gt;no content deleted"; } }else{ if($pageSection==''){ $pageSection="C";} $stmt = $db-&gt;prepare("UPDATE site_content SET box_type=:box_type, box_top=:box_top, box_left=:box_left, box_height=:box_height, box_width=:box_width, content=:content, weblink=:weblink, zindex=:zindex, image_opacity=:image_opacity, border_width=:border_width, border_colour=:border_colour, border_style=:border_style, padding=:padding, shapetype=:shapetype, allPages=:allPages, pageSection=:pageSection WHERE site_ref=:site_ref AND page_ref=:page_ref AND box_id=:box_id"); $stmt-&gt;execute(array(':box_type' =&gt; $type, ':box_top' =&gt; $top, ':box_left' =&gt; $left, ':box_height' =&gt; $height, ':box_width' =&gt; $width, ':content' =&gt; $content, ':weblink' =&gt; $weblink, ':zindex' =&gt; $zindex, 'image_opacity' =&gt; $opacity, ':border_width' =&gt; $borderwidth, ':border_colour' =&gt; $bordercolor, 'border_style' =&gt; $borderstyle, 'padding' =&gt; $padding, 'shapetype' =&gt; $shapetype, 'allPages' =&gt; $allpages, 'pageSection' =&gt;$pageSection, ':site_ref' =&gt; $site_ref, ':page_ref' =&gt; $page_ref, ':box_id' =&gt; $box_id)); $affected_rows = $stmt-&gt;rowCount(); if($affected_rows !=0){ echo "&lt;br&gt;content updated succesfully"; }else{ echo "&lt;br&gt;no content updated"; } } } } </code></pre>
 

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