title: Going from javascript to php to delete multiple rows of MySQL using $_GET with a list of IDs
body: <p>I've spent hours on this one with no luck.  I'm trying to delete list elements that have been marked with a check box and had a delete button press after.  Each checkbox has an html id attribute that correlates the actual ID column value.  I'm using the MySQL statement to remove rows based on the appropriate ids (I can remove the elements from the html but not the MySQL table)</p>
  
  <pre><code>"DELETE FROM todolist WHERE ID IN (".$_GET['id'].")"
  </code></pre>
  
  <p>example id... id="456,444,454"</p>
  
  <p>The javascript goes through and finds the id values of the checked boxes and sends them to a php file.  This part is fine.  From the alert, statement I can verify it's giving the correct ids.  Here's the method called when the delete button is pressed.</p>
  
  <pre><code>function removeCheckedTask(){
  var checkBoxes = $('toDoList').getElementsByClassName('box');
  var deletedID = new Array(); var indexID =0;
  for (var i = 0; i &lt; checkBoxes.length; i++) {
    if (checkBoxes[i].checked){
          deletedID[indexID]=checkBoxes[i].getAttribute('id');indexID++;
          var par = checkBoxes[i].parentNode;
          $('toDoList').removeChild(par);
          i--;
          for(var a=i+1; a&lt;checkBoxes.length; a++){//moves other elements
              par = checkBoxes[a].parentNode;
              par.style.top = (a*40)+"px";
          }
      }
  
  }
  if(deletedID.length&gt;0){
      $('message').innerHTML = "Just a second..."
      // Set te random number to add to URL request
      nocache = Math.random();
      // Pass the login variables like URL variable
      var ids = 'id='+deletedID[0];
      for(var i=1; i&lt;deletedID.length; i++){
          ids+= ',' + deletedID[i];
      }
      alert('removeTasks.php?'+ids);
      http.open('get', 'removeTasks.php?'+ids);
      http.onreadystatechange = deleteReply;
      http.send(null);
      }
      function deleteReply() {
      if(http.readyState == 4){ 
          var response = http.responseText;
          $('message').innerHTML = 'Task removed:'+response;
      }
  }
  
  resetIDs();//resets ids of list elements, don't worry about it
  </code></pre>
  
  <p>}</p>
  
  <p>Here's my php code without the connection stuff.  It makes it into the is statement.</p>
  
  <pre><code>if(isset($_GET['id'])){
     $q+="DELETE FROM todolist WHERE ID IN (".$_GET['id'].")"; //line 13
     mysql_query($q) or die(mysql_error());
  echo "tried to delete stuff";
  } else { 
  echo("Bad delete");
  }
  </code></pre>
  
  <p>The response echo has been varying a bit as I've made changes to the $q string, but as of recently with this simple version it's been printing the MySQL error-</p>
  
  <p>Notice: Undefined variable: q in C:\xampp\htdocs\todo\removeTasks.php on line 13
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1.  How is getting into the if statement and then saying it's undefined?</p>
  
  <p>If I use</p>
  
  <pre><code>"DELETE FROM todolist WHERE ID IN ("+$_GET['id']+")"
  </code></pre>
  
  <p>I get the error- Notice: Undefined variable: q in C:\xampp\htdocs\todo\removeTasks.php on line 13
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '457' at line 1.</p>
  
  <p>457 was the first id.</p>
  
  <p>New around here and to mysql, so let me know if I left anything out.</p>