0

I have a sample script written using CodeIgniter and I used JQuery's $.get() function. $.get() called this PHP script: delete.php

    $id = $_GET['id'];
    $conn = mysqli_connect('localhost', 'root', '', 'table1');
    $qry = "delete from table1 where id = $id";
    $qry_result = mysqli_query($conn, $qry);

How I call delete.php in JQuery: $.get("delete.php", { id : my_id} );. My problem is that delete.php was not executed by $.get(). I am thinking if the cause was due to CodeIgniter's security that you cannot access the scripts directly?

Please help!

9
  • Look in the network tab of the Chrome Dev tools (or Safari or firefox). Are the requests actually being sent? Commented Mar 9, 2013 at 18:26
  • 2
    Why are you using mysqli_* in Codeigniter? Commented Mar 9, 2013 at 18:27
  • @undefined - Please ignore mysqli, my site is configured to run this version but the query / PHP script is working fine. Commented Mar 9, 2013 at 18:29
  • 1
    Okay, you are using a MVC framework, it is not how it's supposed to work, you should use your Controllers and Models, what you are doing is an anti-pattern. Commented Mar 9, 2013 at 18:31
  • is it a codeigniter way...!!! Commented Mar 9, 2013 at 18:32

1 Answer 1

2

First of all if you are new to this MVC framework then at least go and study the introduction & tutorial part for there user guide http://ellislab.com/codeigniter/user-guide/.

Then only you will come to know how to call a controller in that.

But if you want the answer then you can do this in this way:

1.first go and create a controller(e.g. mycontroller) & write a function inside it(e.g. myfunction) and write your code into that part & it is also better that you do not user this mysqli* stuff in MVC.

2.pass the url(e.g. http://[yourhost]/index.php/mycontroller/myfunction) inside $.get() function.

P.S. I am not sure that your CI is configured to use index.php in URL or not. It totally depends upon your configuration. So if it not work for you then try without index.php or take a look into routs.php

Sign up to request clarification or add additional context in comments.

1 Comment

I got it working before you posted your answer, but still thank you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.