title: Check if a mysql field exist and create if not
body: <p>I am implementing the geonames webservice, like this:</p>
  
  <pre><code>$( "#loc_from" ).autocomplete({
      source: function( request, response ) {
          $.ajax({
              url: "http://ws.geonames.org/searchJSON",
              dataType: "jsonp",
              data: {
                  featureClass: "P",
                  style: "full",
                  maxRows: 12,
                  name_startsWith: request.term,
                  searchlang: 'ES'
              },
              success: function( data ) {
                  response( $.map( data.geonames, function( item ) {
                      item.label = item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName;
                      return item;
                  }));
              }
          });
      },
      minLength: 2,
      select: function( event, ui ) {
           ui.item.task = 'new_city';
           $.post('/includes/router.php', ui.item , function(){
  
           });
           $('#id_loc').val(ui.item.gid);
           //alert(ui.item.gid);
      }
  });
  </code></pre>
  
  <p>where in router.php  I have:</p>
  
  <pre><code>case 'new_city':
      /* comprobar si exite */
      $query = "SELECT geonameid FROM geonames";
      if(count(cache_query($query))&gt;0){
          /* Its already in my database */
      }else{
          foreach ($_POST as $key =&gt; $value) {
                      check_field($key);
              echo $key.': '.$value.'&lt;br&gt;';
          }
      }
      /* si no existe, dar de alta*/
      break;
  </code></pre>
  
  <p>So I would like the function <code>check_field($key)</code> to check if the geonames.$key field exists and alter the table and add it.</p>
  
  <p>Is that posible? ( Also, Do you recommend this? )</p>