UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Run Php Script From Access Form Without Opening A Browser Window, Access 2010    
 
   
PeterK
post May 17 2018, 05:23 AM
Post#1



Posts: 968
Joined: 31-December 06



This code runs the php code bs1f.php - but it opens a browser window each time.

CODE
qurl = "http://xxxxxx.com/1605189996/bs1f.php"
Set http = CreateObject("MSXML2", "XMLHTTP")
http.Open "GET", qurl, False


What do I need to change so that no browser window is opened ? Thanks.

Go to the top of the page
 
cheekybuddha
post May 17 2018, 05:34 AM
Post#2


UtterAccess VIP
Posts: 11,514
Joined: 6-December 03
From: Telegraph Hill


Your CreateObject looks strange.

Normally I would expect:
CODE
' ...
  set http = CreateObject("MSXML2.XMLHTTP")
' ...


Otherwise, please post all the code.

hth,

d
Go to the top of the page
 
PeterK
post May 17 2018, 12:18 PM
Post#3



Posts: 968
Joined: 31-December 06



Thanks David

The code that I posted which opened the URL in a browser now gives the runtime error Class not registered on local machine. This morning it worked. Very strange ! It came from this source

Your code runs but does not fire the script (i.e the database changes the script makes don't happen).

The full code isn't much more than I posted

CODE
Private Sub Command0_Click()
qurl = "http://xxxxx.com/160599a/bs1f.php"
'Set http = CreateObject("MSXML2", "XMLHTTP")  ' run time error message
Set http = CreateObject("MSXML2.XMLHTTP") ' no error but fails to run script
http.Open "GET", qurl, False
MsgBox "done"
End Sub


I then remembered I've been here before and found a code snippet which does work - either the POST or GET version


CODE
Private Sub Command0_Click()
770   Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
       Call objHTTP.Open("POST", "http://xxxx.com/518axx8/bs1f.php", False)   ' Use either GET or POST
       'Call objHTTP.Open("GET", "http://xxxxx.com/518axx8/bs1f.php", False)
790   Call objHTTP.send("")
800   tt = objHTTP.responseText
End Sub


References required for code are Microsoft XML v6.0 and Microsoft Internet Controls

Looking again at the source of my original code, I think the MS guy just picked up the typo in the text at the head and maybe assumed the code worked. The difference seems to be using a different object i.e MSXML2.ServerXMLHTTP


Go to the top of the page
 
cheekybuddha
post May 17 2018, 01:09 PM
Post#4


UtterAccess VIP
Posts: 11,514
Joined: 6-December 03
From: Telegraph Hill


Are you able to share the php script?

Are you passing POST parameters to the script?

If so, you will need to code for that too.
Go to the top of the page
 
PeterK
post May 18 2018, 09:05 AM
Post#5



Posts: 968
Joined: 31-December 06



Sure...

This is the one I've been playing with for this post. It doesn't pass any parameters but ( as per the second script) that's straightforward. This one takes data from an Access form and creates a node in a Drupal database. A single click saves to a linked DB and also feeds the Drupal website. Inserting one record is almost instantaenous. Creating 30 nodes this way takes about 10 seconds.

CODE
chdir('../drmp3');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$node = new stdClass();
  $node->title = "Test 1 Title";
  $node->type = "article";
  node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  $node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
  $node->body[$node->language][0]['value']   = "Test1";
  $node->field_custom1[LANGUAGE_NONE][0]['value'] = "PPPP";
  $node->uid = 1;
  $node->status = 1; //(1 or 0): published or not
  $node->promote = 0; //(1 or 0): promoted to front page
  $node->comment = 0; // 0 = comments disabled, 1 = read only, 2 = read/write
  $node = node_submit($node); // Prepare node for saving
  //dsm($node);
  node_save($node);
  echo "Inserted article!";


This example creates a Xero invoice at the same time a updating a MySQL db. The parameters are passed in the URL which is built in the Access script.

CODE
include_once "xero.php";
include_once ("xerokeysmfw.inc");


$xero = new Xero(XERO_KEY, XERO_SECRET, 'publickey.cer', 'privatekey.pem', 'xml' );
$name = $_GET["name"];
$date = $_GET["d1"];
$duedate  = $_GET["d2"];
$status = $_GET["st"];
$lineamounttypes = $_GET["la"];
$description1 = $_GET["de1"];
$quantity1 = $_GET["qy1"];
$unitamount1 = $_GET["ua1"];
$accountcode1 = $_GET["ac1"];
$invoiceid = $_GET["invn"];
$invline = array("Description" => $description1,"Quantity" => $quantity1, "UnitAmount" => $unitamount1,"AccountCode" => $accountcode1,                "TaxType" => "ZERORATEDOUTPUT",    "TaxAmount" => "0");

$new_invoice = array(
        array(
            "Type"=>"ACCREC",
            "InvoiceNumber"=> $invoiceid,
            "Contact" => array(
                "Name" => $name
            ),
            "Date" => $date,
            "DueDate" => $duedate,
            "Status" =>  $status,
            "LineAmountTypes" => $lineamounttypes,
            "LineItems"=> array(
                "LineItem" => array( $invline )
            )
            
        )
    );


$invoice_result = $xero->Invoices( $new_invoice );


I hope this is helpful. Doing these sort of things makes Access a very powerful partner for applications that want the power and speed of a locally installed app. with a web interface - either sharing the same database or maintaining a synchronised data source.
Go to the top of the page
 
cheekybuddha
post May 18 2018, 09:32 AM
Post#6


UtterAccess VIP
Posts: 11,514
Joined: 6-December 03
From: Telegraph Hill


I tried with both "MSXML2.ServerXMLHTTP" and "MSXML2.XMLHTTP" and both worked.

I used this code (virtually identical to yours):
CODE
Function QuickTest(URL As String) As String

  With CreateObject("MSXML2.ServerXMLHTTP")
    .Open "GET", URL, False
    Call .Send
    Debug.Print "Status:", .Status
    QuickTest = .responseText
  End With

End Function


With your first example above I would expect just to return "Inserted article!"

See if you can get this working first.

If not, check what response code is output to the Immediate Window.

Then, just create a simple php file that echoes something:
CODE
<?php

  echo 'Hello PeterK!';

?>


Save as test.php in the root of your web server, and use that as the test URL.

Once you are sure you are getting a response then we can look at parameters.

hth,

d
Go to the top of the page
 
PeterK
post May 20 2018, 01:41 PM
Post#7



Posts: 968
Joined: 31-December 06



You are quite right MSXML2.XMLHTTP works as well. I don't know why I hit a problem - Sorry !

The test script your provided works just as you expected.

I now have a script working with parameters passed by GET as per the second script I posted. That's good. Thanks again for your help.
Go to the top of the page
 
cheekybuddha
post May 20 2018, 05:11 PM
Post#8


UtterAccess VIP
Posts: 11,514
Joined: 6-December 03
From: Telegraph Hill


Brilliant! Great work!

Continued success with your project! thumbup.gif

Shout if you need more help,

d
Go to the top of the page
 
PeterK
post May 23 2018, 10:13 AM
Post#9



Posts: 968
Joined: 31-December 06



Thanks David - but most of this has been down to you !

Thanks for your encouragement.
Go to the top of the page
 
cheekybuddha
post May 23 2018, 02:19 PM
Post#10


UtterAccess VIP
Posts: 11,514
Joined: 6-December 03
From: Telegraph Hill


yw.gif
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th October 2019 - 02:19 PM