0

I'm trying to pass two variables into jQuery's "POST" function, but they don't seem to be getting to my PHP.

<script>
var starting = 0;
var ending = 3;
$(document).ready(function(){               
           $.post("test.php", {start: starting, end: ending}, 
                   function(){});
  });
</script>

It's my understanding that I should be able to access "starting" and "ending" by using $_POST["start"] and $_POST["end"], but it doesn't seem to be working. Am I passing these variables incorrectly? Here's the start of my PHP. The script works fine if I hard-code test values for the limit.

$starting = intval($_POST["start"]);
$ending = intval($_POST["end"]);
$query = "SELECT formation_name FROM formations LIMIT '$starting','$ending'";
3
  • 2
    You are using an obsolete database API and should use a modern replacement. You are also vulnerable to SQL injection attacks that a modern API would make it easier to defend yourself from. Commented Mar 10, 2013 at 20:48
  • By calling intval he should be safe against SQL injections in this example. Although it's a good idea to update to a newer API if it's not too much work. Commented Mar 10, 2013 at 20:49
  • Thanks, I am using the mysqli API though :) I just took the code above to demonstrate my problem, none of this is going into production, just some tests for some front-end scripts I'm working on. Commented Mar 10, 2013 at 20:59

1 Answer 1

7

The MySQL LIMIT clause takes two integers, not strings. Remove the quotes you have around them.

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

1 Comment

This worked, thanks. For some reason, I thought single quotations denoted variables within a query as opposed to strings. Rookie mistake!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.