title: Insert into MySQL through a Buttons OnClick
body: <p>Using a few answers on here I have got row being added to MySQL upon a button press but the data is blank and so I can only assume the variables are not being passed.</p>
  
  <p>I really don't know what I am doing wrong, any help would be greatly appreciated.</p>
  
  <p><strong>PHP</strong>
      </p>
  
  <pre><code>&lt;? $sql = "SELECT itemname FROM items ORDER BY itemname ASC";
  $result = mysql_query($sql);
  
  while ($row = mysql_fetch_array($result)) {
  
  echo "&lt;button onclick='javascript:ajaxCall(" . $row['id'] . ")'&gt;&lt;span class='btn-text'&gt;" . $row['itemname'] . "&lt;/span&gt;&lt;/button&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  function ajaxCall(id){
    $.ajax({
      type: "POST",
      url: "additem.php",
      success: function(data){
      // callback function
  }
  });
  return false;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>additem.php</strong>
      
  
  <pre><code>// Connect database. 
  include("settings.php");
  mysql_connect($db_host,$db_user,$db_pass);
  mysql_select_db($db_name);
  
  $id = $_POST['id'];
  
  $itemsearch = mysql_query("SELECT itemname, itemcategory, price, qty FROM presales WHERE id='$id'");
  $itemsearchrest = mysql_num_rows($itemsearch);
  
  $itemname = $itemsearchrest['itemname'];
  $itemcategory = $itemsearchrest['itemcategory'];
  $price = $itemsearchrest['price'];
  $qty = $itemsearchrest['qty'];
  
  
  $sql = "INSERT INTO presales (itemname, itemcategory, price, qty) VALUES('$itemname', '$itemcategory', '$price', '0')";
  if(mysql_query($sql)){
   return "success!";
  }
  else {
  return "failed!";
  }
  
  ?&gt;
  </code></pre>