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 4593304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:39:53+00:00 2026-05-21T22:39:53+00:00

I have a database table named ‘favoritecats’ with the following fields: id catName catId

  • 0

I have a database table named ‘favoritecats’ with the following fields:

  • id
  • catName
  • catId

I am using Jquery to run this function on click event of an element on DOM Ready.

// Delete a Favorite Category from SQL Database
    $('.deleteCatFavs').click(function(){      // On click of .deleteCatFavs
    var actionRequested = "AJAX_delFavCat";    // My Personal PHP Controller Identifier
    var url = "index.php";                     // URL to post to

// Now Im getting the data I want to post into variables.
    var catId = $("input[name=FavCats]:checked").val();
    var rowId = $("input[name=FavCats]:checked").attr("id");

// Now we make the post
    $.post(url, {AJAX_Action: actionRequested, rowId: rowId},
        function(data){
            $("#favCats").fadeIn().html(data);
           });
    });

This all Works Fine,

But below I have the PHP Code to delete the selected rowId from above from the database.
Here is where im having the issue, Im sure its a SQL error.

public function AJAX_delFavCat(){

$rowId = isset($_POST['rowId'])?$_POST['rowId']:''; // Get Posted Variable
// Below, I want to delete the posted rowId, from the DB,
$this->database->query("DELETE FROM 'favoritecats' WHERE id='$rowId'");

// My personal Loaders, I need help with the delete query above!!
$data = $this->database->query("SELECT * FROM favoritecats");
$this->load->view('Ajax_addToFavCats.php', $data, $ajax=1);

} // End

The “DELETE FROM ‘favoritecats’ WHERE id=’$rowId'” doesn’t work, what am I doing wrong?

[EDIT]
I get the following error through SQL:
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 ”favoritecats’ WHERE id=’27” at line 1

Also, How would I write a Jquery function using the $.ajax method instead of the $.post method im using now, does it really make a difference?

  • 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-05-21T22:39:53+00:00Added an answer on May 21, 2026 at 10:39 pm

    what am I doing wrong?

    You’ve got a SQL-injection security hole.
    See: How does the SQL injection from the "Bobby Tables" XKCD comic work?

    Change this

    $rowId = isset($_POST['rowId'])?$_POST['rowId']:''; // Get Posted Variable
    // Below, I want to delete the posted rowId, from the DB,
    $this->database->query("DELETE FROM 'favoritecats' WHERE id='$rowId'");
    

    To this

    $rowId = isset($_POST['rowId'])?$_POST['rowId']:''; // Get Posted Variable
    $rowId = mysql_real_escape_string($rowId);
    // Below, I want to delete the posted rowId, from the DB,
    $this->database->query("DELETE FROM `favoritecats` WHERE id='$rowId'");
    

    To properly escape your inputs.

    Back to your question

    $this->database->query("DELETE FROM `favoritecats` WHERE id='$rowId'");
    

    Will fix your error.
    Note the use of backticks around tablenames, Normal quotes are not allowed and are in fact a syntax error.

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

Sidebar

Related Questions

I have a database table (named Topics) which includes these fields : topicId name
I have a database with a table named shoppingcarts . this table has the
I have a database Table Named P_Columns. This Table Contains the columns ID Column_Name
I have a database with a table named order . When i run php
I have a database table named call with columns call_time, location, emergency_type and there
I have a table in my Postgres database with columns named type, desc, and
I have a database table and one of the fields (not the primary key)
I Have a DataBase in my project With Table named 'ProcessData' and columns named
I have a Database (SQL Server) with table named 'ProcessData' and columns named 'Process_Name'
Suppose I have a MySQL database named DB, and a table named ContactInfo. The

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.