title: AJAX to call PHP file which removes a row from database?
body: <p>Alright, so I asked a question yesterday regarding how to save the blog posts that a user makes. I figured out the database side of it, and that works fine. Now, I want to REMOVE a blog post based after clicking an onclick button. Through my hours of digging through the web, I've found calling an jQuery AJAX function is the best way to go about it. I've been tooling around with it, but I can't get this working.</p>
  
  <p>Blog code retrieved from database in blog.php:</p>
  
  <pre><code>$connection = mysql_connect("...", "...", "...") or die(mysql_error());
  $database = mysql_select_db("...") or die(mysql_error());
  
  $query = mysql_query("SELECT * FROM template") or die(mysql_error());
  $template = mysql_fetch_array($query);
  
  $loop = mysql_query("SELECT * FROM content ORDER BY content_id DESC") or die (mysql_error());
  while ($row = mysql_fetch_array($loop))
  {
          print $template['Title_Open'];
          print $row['title'];
          print '&lt;button class="deletePost" onClick="deleteRow(' . $row['content_id'] . ')"&gt;Remove Post&lt;/button&gt;';
          print $template['Title_Close'];
  
          print $template['Body_Open'];
          print $row['body'];
          print $template['Body_Close'];
  }
  
  mysqli_close($connection);
  </code></pre>
  
  <p>This creates the following HTML on home.php:</p>
  
  <pre><code>&lt;div class="blogtitle" class="post3"&gt;Title
  &lt;button class="deletePost" onClick="deleteRow(3)"&gt;Remove Post&lt;/button&gt;&lt;/div&gt;
  &lt;div class="blogbody" class="post3"&gt;Content&lt;/div&gt;
  </code></pre>
  
  <p>Which should call my remove.js when button is clicked (This is where I start to lose what I'm doing):</p>
  
  <pre><code>$function deleteRow(id){
      $.ajax({
          url: "remove.php",
              type: "POST",
              data: {action: id}
      });
      return false;         
  };
  </code></pre>
  
  <p>Calling remove.php (No idea what I'm doing):</p>
  
  <pre><code>$con=mysqli_connect("...","...","...","...");
  if (mysqli_connect_errno())
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $id = $_POST['action'];
  
  $query = mysql_query("DELETE FROM content WHERE content_id=$id") or die(mysql_error());
  </code></pre>
  
  <p>My goal here is to REMOVE the row with the ID from the table which would in turn remove the blog post entirely since it won't see the row when it loops through the database table.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks for your help,
  Kyle</p>