0

Amateur here... I have an SQL query on an JS page and need to pass the variables onto a PHP webpage. I know how to pass the more simple variables through the URL, but am struggling in finding and executing the most efficient way to passing a long string, i.e. the text description of a point

Here on the JS side, I have:

downloadUrl("php_genxml1.php", function(data) {
    var xml = data.responseXML;
    var points = xml.documentElement.getElementsByTagName("point");
    for (var i = 0; i < points.length; i++) {
      var id = points[i].getAttribute("id");
      var name = points[i].getAttribute("name");
      var description = points[i].getAttribute("description");
      var url = "PHPWebPage.php?name=" + name + "&id=" + id;

To get the id from the URL, I have used stuff like the standard

$id=$_GET['id'];

I know I could re run a query based off that id from the URL, but that surely doesn't sound the most efficient. I know my options (array, sessions, etc) for whatever that's worth.

Thanks for any help, C

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
ambe5950
  • 75
  • 2
  • 11
  • You want to pass a SQL query to the server? You should never never never do that. You would be given any user full access to the database. – epascarello Oct 08 '14 at 18:13
  • You can send a longer description without any problems, just make sure you `encodeURIComponent()` the values. If it really gets too long (hard to imagine for a point description...), you can POST instead of GET. About the maximum length: http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request – jeroen Oct 08 '14 at 18:20

1 Answers1

1

Try POSTing the data instead. It also makes it less likely for someone to just edit your URL in the browser to get data they're not supposed to have.

ariscris
  • 533
  • 1
  • 4
  • 19
  • This. `GET` request sizes are usually limited to a few kilobytes, `POST` request limits are usually at least a few megabytes. – Sammitch Oct 08 '14 at 18:18