title: Run PHP SQL query command when link clicked on
body: <p>I want there to be a SQL query to take place when a link is clicked on, so far this is what I have:</p>
  
  <p>mainpage.php:</p>
  
  <pre><code>function deleteImage1() {
      $.post("delete_image.php", { num:1, id:&lt;?php echo $id; ?&gt; }, function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
    });
      return false;
  }
  
  &lt;a href="#" onclick="deleteImage1()"&gt;Delete Image&lt;/a&gt;
  </code></pre>
  
  <p>delete_image.php:</p>
  
  <pre><code>&lt;?php
  
  // $connect stuff here 
  
      $num = $_GET['num'];
      $id = $_GET['id'];
  
      if ($num === '1') {
      $image_num == '';
      } else {
      $image_num == $num;
      }
  
      $sqlCommand = mysql_query("UPDATE alpacas1 SET image$image_num='' WHERE id=$id");
  
  if (!$sqlCommand) {
      die('Invalid query: ' . mysql_error());
  } else {
   echo "Updated successfully!";
  }
  ?&gt;
  </code></pre>
  
  <p>Now, when I click on the "Delete Image" link, it try's to run the function, and it does, but returns as this in the popup:</p>
  
  <blockquote>
    <p>Data: Invalid query: You have an error in your SQL syntax; check the
    manual that corresponds with your MySQL server version for the right
    syntax to use near " at line 1. <br />
    Status: success</p>
  </blockquote>
  
  <p>But when I reload the page, (or look in the database), the image field has not been changed to '' (or null).</p>
  
  <p>Also, I have tested the SQL query so it is not that. I have done so by visiting delete_image.php in my browser with the id &amp; num variables being "posted" (ex. delete_image.php?num=1&amp;id=20) and by visiting it IN BROWSER, it SUCCESSFULLY deletes the image and gives me the message "Updated successfully!". </p>
  
  <p>I'm guessing it's something with my Javascript as I am a beginner! Thanks for your help!</p>