473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Pass variables to PHP from VBA?

First of all I apologise if this is the wrong place to post this; if it fits better somewhere else, could you either tell me, or could a mod move it for me. Thanks.


Access 2003

I've set up a phone system (using trixbox if anyone's familiar with it); and I'd like to be able to click a button on our database which will send the phone number to the phone to dial, without having to type the number in.

The first code below is the php that works, if I have it programmed into the phone and hard-code the number and the IP address (x'd out for security). Of course this makes it work for one phone, with one number.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. function push2phone($server,$phone,$data) 
  3. $xml2 = "xml=$data"; 
  4. $post = "POST / HTTP/1.1\r\n"; 
  5. $post .= "Host: $phone\r\n"; 
  6. $post .= "Referer: $server\r\n"; 
  7. $post .= "Connection: Keep-Alive\r\n"; 
  8. $post .= "Content-Length: ".strlen($xml2)."\r\n\r\n"; 
  9. #echo $post; 
  10. $fp = @fsockopen ( $phone, 80, $errno, $errstr, 5); 
  11. if($fp) 
  12. @fputs($fp, $post.$xml2); 
  13. flush(); 
  14. fclose($fp); 
  15. ############################## 
  16. $xml = "<AastraIPPhoneTextScreen>\n"; 
  17. $xml .= "<Title>Push test</Title>\n"; 
  18. $xml .= "<MenuItem>Call Customer\n"; 
  19. $xml .= "<Prompt>Call CustName</Prompt>\n"; 
  20. $xml .= "<Dial>90xxxxxxxxxx</Dial>\n"; 
  21. $xml .= "</MenuItem>\n"; 
  22. $xml .= "</AastraIPPhoneTextScreen>\n"; 
  23. push2phone("10.0.0.xxx","10.0.0.xxx",$xml); 
  24. echo $xml; 
  25. ?>
The following is the query I'd like to run in access, and pass the results to the PHP. The form links are correct and if I run this, it comes up with the correct formatting etc.
Expand|Select|Wrap|Line Numbers
  1. CustName = Forms![Edit Cust].[CustName]
  2. Number = Forms![Edit Cust].Number
  3. Mob = Forms![Edit Cust].Mob
  4. ext = 212
  5. If IsNull(Number) = False Then
  6.     MenuNumber = "<MenuItem>" & vbCrLf & _
  7. "<Prompt>Call " & CustName & "</Prompt>" & vbCrLf & _
  8. "<URI>9" & Number & "</URI>" & vbCrLf & _
  9. "</MenuItem>" & vbCrLf
  10. Else: MenuNumber = ""
  11. End If
  12.  
  13. If IsNull(Mob) = False Then
  14.     MenuMob = "<MenuItem>" & vbCrLf & _
  15. "<Prompt>Call " & CustName & " Mobile</Prompt>" & vbCrLf & _
  16. "<URI>9" & Mob & "</URI>" & vbCrLf & _
  17. "</MenuItem>" & vbCrLf
  18. Else: MenuMob = ""
  19. End If
  20.  
  21. myxml = "xml=<AastraIPPhoneDirectory>" & vbCrLf & _
  22. "<Title>Call Customer</Title>" & vbCrLf & _
  23. MenuNumber & MenuMob & _
  24. "</AastraIPPhoneDirectory>"
So; is there anyway I can push that to the PHP, or recode the PHP into VBA?

Thanks
Mandi
Sep 16 '08 #1
12 7036
NeoPa
32,556 Expert Mod 16PB
Mandi, I don't know PHP at all, but some of the concepts seem clear just by looking at it.

Would I be right in thinking that your aim in the VBA code is to create a large string where all the earlier PHP code is stored. The exception being that line #25 of your PHP code (in the string) is actually set to the number from your form?
Sep 16 '08 #2
Mandi, I don't know PHP at all, but some of the concepts seem clear just by looking at it.

Would I be right in thinking that your aim in the VBA code is to create a large string where all the earlier PHP code is stored. The exception being that line #25 of your PHP code (in the string) is actually set to the number from your form?
Sort of. The VBA is set up to make the xml to be passed to the phone; populating the relevant areas with numbers and names if they exist, and excluding that section if they don't. Hence the three sections; one for phone, one for mobile, one to pull it all together.
So yes, that's the string I need.

I can understand the PHP, I know what it does, I just don't know how I can change the hardcoded xml to the variable xml from the VBA. (Explaining myself has never been my strong point; I apologise)

To run the PHP from the phone I program the button to go to the URL http://xx.xx.xx.xx/callfromdb.php which is the phone server IP and name of the PHP file.
So I assume I need to post the XML and relevant phones IP (based on the user; I can sort that with a table and DLookUp) to the PHP to be inserted into the relevant places.

I've been looking at this site here which is where I got the PHP from. Pages 14 and 44 are most relevant I think.

Does this make sense?
Sep 17 '08 #3
I think that I need to think of this like form data. I need to name it.
For example, if I used the vba to name the xml 'xmlstring' and the relevant IP address 'phoneip', then, in the PHP, if I called them with something like
Expand|Select|Wrap|Line Numbers
  1. $xml= $_POST['xmlstring'];
  2. $phone= $_POST['phoneip'];
Then that *should* work, I think.

But how do I go about naming things like that in VBA?
I think there's something I could do with the SetRequestHeader, but when I try I just keep getting errors; so either I'm way off the mark or I'm not setting it right.
Sep 17 '08 #4
FishVal
2,653 Expert 2GB
Hello, Mandi.

I have little to nothing knowledge in PHP.
Though I suspect you couldn't "push that to the PHP". The very idea seems to me bizzare.

Access could hardly call a procedure on PHP server. The only conventional way to do it (not sure, its only my guess) is to open php link via FollowHyperlink() VBA function.

The rest should be done by PHP code. It should query database for a value stored in a known location - special table or query exposing a single value or more general table where relevant record could be find/recognized by PHP code.

One more point.

Again, I'm not sure, but it may be possible to write to a socket in VBA code as it is an ordinary file (worth trying anyway). If not, then it may be possible in any other way to do it.

Regards,
Fish
Sep 17 '08 #5
Hello, Mandi.

I have little to nothing knowledge in PHP.
Though I suspect you couldn't "push that to the PHP". The very idea seems to me bizzare.

Access could hardly call a procedure on PHP server. The only conventional way to do it (not sure, its only my guess) is to open php link via FollowHyperlink() VBA function.

The rest should be done by PHP code. It should query database for a value stored in a known location - special table or query exposing a single value or more general table where relevant record could be find/recognized by PHP code.

One more point.

Again, I'm not sure, but it may be possible to write to a socket in VBA code as it is an ordinary file (worth trying anyway). If not, then it may be possible in any other way to do it.

Regards,
Fish
Thanks for your reply.
I have little knowledge in most coding unfortunately.
I've been looking at php tutorials in an attempt to understand anything, but I keep coming to the block that pretty much everything it mentions is to do with form-data on websites.

The more I look around, the more confused I get.
The database we have the numbers in is access 2003, front end on each person PC, back end (including the table with the numbers in) on the server.
The phones each have their own IP (Aastra 55i IP phones) and are connected via trixbox which is another computer (running linux OS).

The php file is saved on the trixbox computer.
I want the number to be based on the record that the user is looking at on their computer.
And it has to dial on their phone, not someone elses.

With no knowledge of php, and not much of vba, I'm sure you can see why I thought the 'pushing to php' would work as I can't for the life of me figure out how to tell the computer "this user wants that number. dial it on their phone."

I have been told that it is possible to set something up so that a hyperlink can be used (http://phoneipaddress?number=01234567891), but the person who told me that just said "you'd have to write some xml glue". A week after asking for clarification I still have no reply.

Has anyone come accross anything like this; or has any idea where I can continue to look?
Sep 17 '08 #6
NeoPa
32,556 Expert Mod 16PB
Mandi,

It's very important that the questions are treated as strictly logical questions. This is like cross-roads and I need to know which route to take. "Sort of yes I suppose, I really want to go there (points)" does not help me to decide which road to take. It simply leaves me needing to ask more questions. If we're lucky I can eventually pin down a route. Otherwise I am for ever trying to get beyond explanations phrased in terms for which I have no reference.

Let me try another approach. I will put down some fairly basic VBA which produces a string in the variable strMyXML. What I want you to do is to see if you can get this string to work as PHP (Your code gives no example of how the string is used to produce provide PHP which can be executed). You will of course, need to change the code manually to reflect the variable items in the code (such as phone number etc). I imagine this should be very straightforward.

If we can prove this concept (I'm interested to see how you enable your PHP code), then we can then go forward and look at what's needed for including the values from a form into your PHP string.
Expand|Select|Wrap|Line Numbers
  1. Dim strMyXML As String
  2. ...
  3. strMyXML = "<?php" & vbCRLF
  4. strMyXML = strMyXML & "#" & vbCRLF
  5. strMyXML = strMyXML & "function push2phone($server,$phone,$data)" & vbCRLF
  6. strMyXML = strMyXML & "{" & vbCRLF
  7. strMyXML = strMyXML & "$xml2 = ""xml=$data"";" & vbCRLF
  8. strMyXML = strMyXML & "$post = ""POST / HTTP/1.1\r\n"";" & vbCRLF
  9. strMyXML = strMyXML & "$post .= ""Host: $phone\r\n"";" & vbCRLF
  10. strMyXML = strMyXML & "$post .= ""Referer: $server\r\n"";" & vbCRLF
  11. strMyXML = strMyXML & "$post .= ""Connection: Keep-Alive\r\n"";" & vbCRLF
  12. strMyXML = strMyXML & "$post .= ""Content-Length: "".strlen($xml2).""\r\n\r\n"";" & vbCRLF
  13. strMyXML = strMyXML & "#echo $post;" & vbCRLF
  14. strMyXML = strMyXML & "$fp = @fsockopen ( $phone, 80, $errno, $errstr, 5);" & vbCRLF
  15. strMyXML = strMyXML & "if($fp)" & vbCRLF
  16. strMyXML = strMyXML & "{" & vbCRLF
  17. strMyXML = strMyXML & "@fputs($fp, $post.$xml2);" & vbCRLF
  18. strMyXML = strMyXML & "flush();" & vbCRLF
  19. strMyXML = strMyXML & "fclose($fp);" & vbCRLF
  20. strMyXML = strMyXML & "}" & vbCRLF
  21. strMyXML = strMyXML & "}" & vbCRLF
  22. strMyXML = strMyXML & "##############################" & vbCRLF
  23. strMyXML = strMyXML & "$xml = ""<AastraIPPhoneTextScreen>\n"";" & vbCRLF
  24. strMyXML = strMyXML & "$xml .= ""<Title>Push test</Title>\n"";" & vbCRLF
  25. strMyXML = strMyXML & "$xml .= ""<MenuItem>Call Customer\n"";" & vbCRLF
  26. strMyXML = strMyXML & "$xml .= ""<Prompt>Call CustName</Prompt>\n"";" & vbCRLF
  27. strMyXML = strMyXML & "$xml .= ""<Dial>90xxxxxxxxxx</Dial>\n"";" & vbCRLF
  28. strMyXML = strMyXML & "$xml .= ""</MenuItem>\n"";" & vbCRLF
  29. strMyXML = strMyXML & "$xml .= ""</AastraIPPhoneTextScreen>\n"";" & vbCRLF
  30. strMyXML = strMyXML & "push2phone(""10.0.0.xxx"",""10.0.0.xxx"",$xml);" & vbCRLF
  31. strMyXML = strMyXML & "echo $xml;" & vbCRLF
  32. strMyXML = strMyXML & "?>" & vbCRLF
  33. Call MsgBox(strMyXML)
The MsgBox() call at the end is to make sure that this is exactly as you expect it to be (barring possible line-wraps).

Do whatever you need to do after that to get it to be used and let us know if it works. If so, we have a way forward. If not, then either one of us has made a mistake somewhere, or the concept is fundamentally wrong & I understood you even less well than I thought ;)
Sep 17 '08 #7
FishVal
2,653 Expert 2GB
...
I have been told that it is possible to set something up so that a hyperlink can be used (http://phoneipaddress?number=01234567891), but the person who told me that just said "you'd have to write some xml glue"....
That definitely makes sense.
Though I know nothing in web development, I'm aware of that arguments may be passes via link. That makes my previous suggestion having more sense.
The whole logic becomes tight:
  • In Access code create in a table, let us say [tblCalls] a record based on values generating via VBA code you've posted above and containing all necessary information for PHP code to make its job.
  • Using FollowHyperlink() VBA function open a link with your PHP procedure passing primary key of [tblCalls] as argument in link.
  • In PHP code query Access database to get record from [tblCalls] where primary key is what you've passed in link.

I could help you with p.1.
As for pp. 2,3 you should better ask question on PHP forum.

Regards,
Fish
Sep 17 '08 #8
Thanks NeoPa.

I'll go play with that see if I can get it to do something.

I've always found that my biggest problem with anything is that I know how I want it to be/work/look, I just can't explain it very well.

I think with all the hunting I've been doing over the last couple of weeks I've just confused myself beyond help lol

It would be much easier for me to explain if someone had experience / knowledge of trixbox and aastra phones, but when I try to get help on those forums I just get told to try the exact thing that I originally stated in my first post.

I'll scoot and try things now.
Thanks all for your help
Sep 17 '08 #9
  • In Access code create in a table, let us say [tblCalls] a record based on values generating via VBA code you've posted above and containing all necessary information for PHP code to make its job.
  • Using FollowHyperlink() VBA function open a link with your PHP procedure passing primary key of [tblCalls] as argument in link.
  • In PHP code query Access database to get record from [tblCalls] where primary key is what you've passed in link.
That sounds logical.
To generate the values I guess it's as simple as an append query with the critera set to the open forms customer number, and selecting the customer number, phone number and possibly mobile number if I eventually get it working okay.
I think I can work most of that, but I think you're right about moving to a PHP board.

Thank you for all your help, and thank you for putting up with my incredibly bad explanations.

Mandi
Sep 17 '08 #10
NeoPa
32,556 Expert Mod 16PB
No worries Mandi.

I'm sure if you can provide the answers I need then we have a good path forwards :)
Sep 17 '08 #11
NeoPa

Thanks for your help, but I've found a solution.
I think I was over-complicating things.
Solution at this thread

Thanks for trying to help, and for putting up with my bad explanations ;)

Mandi
Sep 17 '08 #12
NeoPa
32,556 Expert Mod 16PB
No worries Mandi. You got your solution and that's the main thing :)
Sep 17 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: adolf garlic | last post by:
Suggestions please for strategy to share values across app. Scenario: I have an asp.net app that uses some com components along with .net classes. Configuration settings for various things...
10
by: tshad | last post by:
I want to access multiple arguments based on name passed. For example I have the following asp:textboxes: BillingAddress1 BillingAddress2 BillingCity ShippingAddress1 ShippingAddress2...
7
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
17
by: Daniel | last post by:
When I use the CreateThread API method, what do I need to do when I want to pass more than one parameter where LPVOID lpParameter is passed? Daniel
21
by: raylopez99 | last post by:
In the otherwise excellent book C# 3.0 in a Nutshell by Albahari et al. (3rd edition) (highly recommended--it's packed with information, and is a desktop reference book) the following statement is...
1
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.