title: Store associative array in database using serialize in php
body: <p>I already asked this before and now I know how to serialize it. But now the problem is I am having this error:</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''address1t', 'address2t', 'cityt', 'provincet', 'postalCODEt', 'contactNOt', 'em' at line 1
  </code></pre>
  
  <p>This is my associative array:</p>
  
  <pre><code>Array ( [0] =&gt; Array ( [recNAME] =&gt; NAME1 [company] =&gt; [address1] =&gt; ADDRESS1 [address2] =&gt; [city] =&gt; CITY1 [province] =&gt; PROVINCE1 [postalCODE] =&gt; 0 [contactNO] =&gt; 926XXXXX [email] =&gt; XXXXX@yahoo.com [commodity] =&gt; COMMODITY1 [type] =&gt; [weight] =&gt; 0 [length] =&gt; 0 [width] =&gt; 0 [height] =&gt; 0 [decVAL] =&gt; 0 [specINSTRUC] =&gt; [shipREF] =&gt; REF1 [payMETHOD] =&gt; CashOnDelivery [packNO] =&gt; 200XXXX-XXX [trackNO] =&gt; 200XXXX-XXX ) [1] =&gt; Array ( [recNAME] =&gt; NAME2 [company] =&gt; [address1] =&gt; ADDRESS2 [address2] =&gt; [city] =&gt; CITY2 [province] =&gt; PROVINCE2 [postalCODE] =&gt; 0 [contactNO] =&gt; 905XXXXXX [email] =&gt; XXXXX@hotmail.com [commodity] =&gt; COMMODITY2 [type] =&gt; [weight] =&gt; 0 [length] =&gt; 0 [width] =&gt; 0 [height] =&gt; 0 [decVAL] =&gt; 361 [specINSTRUC] =&gt; I'm in the above given address from M-F, 11AM-6PM, call or text me for confirmation [shipREF] =&gt; 200XXXXX [payMETHOD] =&gt; CashOnDelivery [packNO] =&gt; 200XXXX-XXX [trackNO] =&gt; 200XXXX-XXX ) )
  </code></pre>
  
  <p>And the serialized array looks like this:</p>
  
  <pre><code>a:4:{i:0;a:21:{s:7:"recNAME";s:18:" NAME1";s:7:"company";s:0:"";s:8:"address1";s:57:"ADDRESS1";s:8:"address2";s:0:"";s:4:"city";s:8:"CITY1";s:8:"province";s:8:"PROVINCE1";s:10:"postalCODE";s:1:"0";s:9:"contactNO";s:10:"9XXXXXXXX";s:5:"email";s:21:"XXXX@yahoo.com";s:9:"commodity";s:13:"COMMODITY1";s:4:"type";s:0:"";s:6:"weight";s:1:"0";s:6:"length";s:1:"0";s:5:"width";s:1:"0";s:6:"height";s:1:"0";s:6:"decVAL";s:2:"99";s:11:"specINSTRUC";s:0:"";s:7:"shipREF";s:9:"200XXXX";s:9:"payMETHOD";s:14:"CashOnDelivery";s:6:"packNO";s:14:"200XXXX-XXX";s:7:"trackNO";s:14:"200XXXX-XXX";}i:1;a:21:{s:7:"recNAME";s:32:" NAME2";s:7:"company";s:0:"";s:8:"address1";s:52:"ADDRESS1";s:8:"address2";s:0:"";s:4:"city";s:6:"CITY2";s:8:"province";s:12:"PROVINCE2";s:10:"postalCODE";s:1:"0";s:9:"contactNO";s:10:"9XXXXXX";s:5:"email";s:23:"XXXX@hotmail.com";s:9:"commodity";s:7:"Spyder ";s:4:"type";s:0:"";s:6:"weight";s:1:"0";s:6:"length";s:1:"0";s:5:"width";s:1:"0";s:6:"height";s:1:"0";s:6:"decVAL";s:3:"361";s:11:"specINSTRUC";s:83:"I'm in the above given address from M-F, 11AM-6PM, call or text me for confirmation";s:7:"shipREF";s:9:"200XXXXX";s:9:"payMETHOD";s:14:"CashOnDelivery";s:6:"packNO";s:14:"200XXXX-XXX";s:7:"trackNO";s:14:"200XXXX-XXX";}}
  </code></pre>
  
  <p>And this is my code on serializing it:</p>
  
  <pre><code>$newstring = serialize($array);
  @mysql_query("INSERT INTO `temp` (`recNAMEt`, `companyt`, 'address1t', 'address2t', 'cityt', 'provincet', 'postalCODEt', 'contactNOt', 'emailt', 'commodityt', 'typet', 'weightt', 'lengtht', 'widtht', 'heightt', 'decVALt', 'specINSTRUCt', 'shipREFt', 'payMETHODt', 'packNOt', 'trackNOt' ) VALUES('', $newstring)") or die('Error: ' . mysql_error()); 
  </code></pre>
  
  <p>This is my first time to serialize and I am still getting a handle on things. I still don't know what went wrong because this code worked for a normal array. I tried doing this:</p>
  
  <pre><code>VALUES('', '', $newstring)")
  </code></pre>
  
  <p>still no luck. The recNAMEt, companyt, etc are column names in my table. Please help. Thanks and regards.</p>