title: Auto generate array from column
body: <p>I am making a form that builds itself from a given db and table. However I have come across a snag when it comes to the Insert function. I already made it so that all the fields generate input, textareas what have you on a page with the correct name. Now all I need to do is insert it into the db on post. But I need to recreate the array in format (this,that,this) using implode and I'm not sure how to do this.</p>
  
  <pre><code> $resultInsert = mysql_query("SHOW COLUMNS FROM " . $table);
  $fieldnames=array();
  
  if (mysql_num_rows($resultInsert) &gt; 0) {
          while ($row = mysql_fetch_array($resultInsert)) {
              echo $fieldnames[] = $row['Field']; #currently outputting titlebodytextcreated (three fields i have)
          }
        }
  
  
  // FORMAT: field_name = $_POST[fieldname]
  
  $values = array('title'=&gt;$_POST['title'],'bodytext'=&gt;$_POST['bodytext']); # need this to be autogenerated by the field names
  
  echo "&lt;br&gt;" . sprintf('INSERT INTO %s (%s) VALUES ("%s")', 'testdb', 
  implode(', ', array_map('mysql_escape_string', array_keys($values))), implode('", "',array_map('mysql_escape_string', $values))); 
  
  // add loop for id to be generated in a hidden field, along with all other excluded fields so that the
  // update will process correctly in the insert into phase
  </code></pre>