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

  • SEARCH
  • Home
  • 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 7790871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:43:17+00:00 2026-06-01T21:43:17+00:00

Hey I have a problem in Javascript-PHP variable passing heres my php code: <li

  • 0

Hey I have a problem in Javascript-PHP variable passing
heres my php code:

<li id="' . $todo1 . '" class="items">' . $todo1 . '<button onclick="ajaxdelete(' . $todo1 . ')">Delete</button></li>

and heres the javascript function

 function ajaxdelete(x){
var hr = new XMLHttpRequest();
var url = "ajaxtododelete.php";
var vars = "todo="+x;
hr.open("POST", url, true);

hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
 }
 hr.send(vars); // Actually execute the request

} 

and hers my ajax file:

<?php
session_start();
include_once "connect_to_mysql.php";
$todo = $_POST['todo'];
print "$todo";

$sql = mysql_query("DELETE FROM todo WHERE todo='$todo'");
?>

So instead of outputting the value of ‘$todo1′(which is wat i want) it outputs :
object HTMLLIElement.Any way around this?

  • 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-01T21:43:19+00:00Added an answer on June 1, 2026 at 9:43 pm

    First, you have a major hole in your application for SQL injection. Second, you need to quote the identifer so you are passing the value of the id in the function call instead of a reference to the element itself. Third, you probably ought to be using a framework for this and applying the handlers unobtrusively.

    '<li id="' . $todo1 . '" class="items">' . $todo1 . '<button onclick="ajaxdelete(\'' . $todo1 . '\')">Delete</button></li>'
    

    better (using jQuery)

    '<li id="' . $todo1 . '" class="items">' . $todo1 . '<button>Delete</button></li>'
    
    
    <script type="text/javascript">
         $(function() {
               $('.items').on('click', function() {
                   var $li = $(this).closest('li');
                       id = $li.attr('id');
                   $.post( "ajaxtodelete.php", { "todo" : id }, function() {
                           $li.remove();
                   });
               });
         });
    </script>
    

    And fix your PHP to use a parameterized query instead of string concatenation in case someone decides to modify the ids using a browser debugger and change the id in to a SQL command that will drop your entire database — or retrieve its contents for more nefarious purposes.

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

Sidebar

Related Questions

Hey there, i got this very annoying problem: I have a CheckBoxList getting items
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
hey I have a small problem with my rake class CreateEvents < ActiveRecord::Migration def
Hey guys, I have a problem with a code that I've been writing. I
Hey I have a problem comparing the value of a CGPoint (struct with two
Hey I have a problem with the validation and upload of apps to the
Hey all, i have a problem with trying to get 2 forms to close
Hey guys, I have a weird problem. I have an update system that refreshes
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
Hey all, i have been trying for a few minutes on this problem and

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.