Drupal 6 parses incoming POST data

I have an Excel file that I need to send data from my Drupal MySql database. For this I am using HTTP POST from VBA of my Excel sheet like this:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
        URL = "http://localhost:8082/acquia-drupal/node/2"
        objHTTP.Open "POST", URL, False
        objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
        objHTTP.send ("string=testdata")

      

I want to use a Drupal page that will parse the POST data and write it to a table in the Drupal MySql database.

This is what I started with

<?php
if (isset($_POST['string']))
{
  $trans = $_POST['string'];
  db_query("INSERT INTO {excel} (ExcelData) VALUES (%d')",
  $trans);
}

      

Is this the right direction? Also, can anyone provide guidance on code snippets to handle POST data correctly?

+2


source to share


2 answers


Handling incoming $ _POST data, as you outline, is a bit like manually delivering your own web service. It's not bad, it's necessary, and sometimes it's the best way to get things to talk to each other.

I would strongly emphasize that you are responsible for your own security, data cleansing and SQL injection protection if you use code like this in the snippet posted.



Also, as noted in Eli's comment, it seems like you can put it in node. This is a relatively dangerous way to do it, as anyone can easily open that node open and firehosing $ _POST the data into your database. Creating a module with hook_menu () to define a URL for your import code and limiting some restrictions on access to that URL will make things safer.

+5


source


At this point, it looks like you are just writing this code in a PHP filter page.

If this is indeed the case, this is not a good idea. At least write a custom module, perhaps with some POST-parsing code in the hook_view (or just with a simple custom function) and using hook_menu to set the page url.



As far as POST parsing is concerned, it's a PHP array of key => value ... I haven't found a way to use Drupal-ish, and some popular modules certainly use it as is.

+1


source







All Articles