title: Run a SQL function when Publishing a post in Wordpress and populate fields according to Custom field meta
body: <p>I would like to run an sql query whenever i publish a post. Im just not sure how to wrap it in a function and where to paste that function to take effect that when i click publish.
  The following command, which is the one i need, runs successfully in phpMyAdmin- SQL, and it also reflects correctly in my wordpress backend.</p>
  
  <pre><code>INSERT INTO  `databasename`.`wp_xxxxxx` (
  `id` ,
  `name` ,
  `item_number` ,
  `price` ,
  `options_2`) VALUES (
  '9',  'xxxx1',  'xxxx2',  'xxxxx3', 'xxxx4'
  );
  </code></pre>
  
  <p>But, how do i get this to run in PHP, in my functions.php file when i save a post each time?
  I tried the following, but i'm sure its correct because i do a refresh afterwards and the tables are not created:</p>
  
  <pre><code>function do_my_stuff($post_ID)  {
  mysql_query("INSERT INTO  `databasename`.`wp_xxxxx` (
  `id` ,
  `name` ,
  `item_number` ,
  `price` ,
  `options_2`) VALUES (
  '9',  'xxxx1',  'xxxx2',  'xxxx3', 'xxxxx4'");
     return $post_ID;
  }
  </code></pre>
  
  <p>add_action('save_post', 'do_my_stuff');</p>
  
  <p>When a post is published. It is actually a product that needs some details. </p>
  
  <p>Here are my desired VALUES for the sql query to populate.</p>
  
  <ul>
  <li>id = the postID number of the post.</li>
  <li>name = the post title </li>
  <li><p>item_number = it should be a custom field post meta value, coming
  from a field named 'scode', at the moment i echo it on my single page template via:  </p>
  
  ID, 'scode', true) ) echo
     do_shortcode(get_post_meta($post->ID, 'scode', $single = true)); ?></li>
  <li><p>price = the price, which i also manually enter via a custom field
  called 'price' which i currently echo via :</p>
  
      </li>
  <li><p>options_2, which i also manually enter via a custom field value
  called 'variations'.</p></li>
  </ul>
  
  <p>Can all this be done like in this way?</p>
  
  <p>Perhaps something like:</p>
  
  <pre><code> INSERT INTO  `databasename`.`wp_cart66_products` (
      `id` ,
      `name` ,
      `item_number` ,
      `price` ,
      `options_2`) VALUES (
      '9',  '&lt;?php the_title(); ?&gt;',  '&lt;?php if ( get_post_meta($post-&gt;ID, 'scode', true) ) echo do_shortcode(get_post_meta($post-&gt;ID, 'scode', $single = true)); ?&gt;',  '&lt;?php $values = get_post_custom_values("price"); echo $values[0]; ?&gt; ', '&lt;?php $values = get_post_custom_values("variations"); echo $values[0]; ?&gt;   '
      );
  </code></pre>
  
  <p>Please note that i don't very little about php, or SQL. I spend hours trying to find as much possible information as i can to provide a solid request.</p>