Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:43:02+00:00 2026-06-08T17:43:02+00:00

I’ve spent hours on this one with no luck. I’m trying to delete list

  • 0

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)

"DELETE FROM todolist WHERE ID IN (".$_GET['id'].")"

example id… id=”456,444,454″

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.

function removeCheckedTask(){
var checkBoxes = $('toDoList').getElementsByClassName('box');
var deletedID = new Array(); var indexID =0;
for (var i = 0; i < 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<checkBoxes.length; a++){//moves other elements
            par = checkBoxes[a].parentNode;
            par.style.top = (a*40)+"px";
        }
    }

}
if(deletedID.length>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<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

}

Here’s my php code without the connection stuff. It makes it into the is statement.

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");
}

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-

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?

If I use

"DELETE FROM todolist WHERE ID IN ("+$_GET['id']+")"

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.

457 was the first id.

New around here and to mysql, so let me know if I left anything out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:43:05+00:00Added an answer on June 8, 2026 at 5:43 pm

    You get a notice because your variable “q” wasn’t defined and you try to add something to it. And you get an sql error because “+” is for numbers in php unlike in javascript. So your sql statement probably gets converted to a zero, and thats why you get the “0” error. The correnct way would be:

    $q .= "DELETE...";
    

    Also I would rather recommend calling each query separately since then you can get back the result (or the error) of each:

     $q = null;
     $ids = explode(",",$_GET["id"]);
     foreach($ids as $id) {
          $id = (int)$id; //VERY basic security thing
          $q = "DELETE FROM todolist WHERE ID = ".$id;
          mysql_query($q) or die(mysql_error());
     }
    

    Are you learning php or is it an actual application? Because as someone said earlier this is not a good way to do this. GET shouldn’t be used for anything which has permanent changes on your data. You should have a POST form and some hidden field to check if the request actually came from that form.
    And you should use mysql escape functions since anything could be inserted after your query. Look up mysql injections for more info.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.