By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Sending data form a vb program too a mysql DB

P: n/a
Hello, as this falls under both VB and PHP I have posted this into two
newsgroups (this is the first time I've done this so if it is mucked up
then I'm sorry).

Anyway I want to make some simple games with in VB 6.0 and then I want
the highscores to go to the server (which uses PHP and MySQL). And if
its possible I would also like the highscores to be viewable on the
program AND on my site.

PHP Part:
I think I need to set MySQL up so it can be accesssed from outside of
the server, but I'm not sure.

Thanks, James.

Nov 14 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
James wrote:
Hello, as this falls under both VB and PHP I have posted this into two
newsgroups (this is the first time I've done this so if it is mucked
up then I'm sorry).

Anyway I want to make some simple games with in VB 6.0 and then I want
the highscores to go to the server (which uses PHP and MySQL). And if
its possible I would also like the highscores to be viewable on the
program AND on my site.

PHP Part:
I think I need to set MySQL up so it can be accesssed from outside of
the server, but I'm not sure.
Are you saying that your VB apps are installed on the users machines,
but that you want the high-scores to be saved on the mySQL database
residing on your web-server?

If so, write a php-script that takes i.e. username and highscore as
params, and make that phpscript do the db-writing on the server.

From vb, use the XmlHttp object or one of its siblings to POST
the data to this php-script on the server.

To view the high-scores, use the same principle. (Do it from php, and
when your vb client needs it, Use HTTP).

--
Dag.

Nov 14 '06 #2

P: n/a

"Dag Sunde" <me@dagsunde.comwrote in message
news:45***********************@news.wineasy.se...
>
From vb, use the XmlHttp object or one of its siblings to POST
the data to this php-script on the server.

To view the high-scores, use the same principle. (Do it from php, and
when your vb client needs it, Use HTTP).
Dag, how much data is reasonable to move back and forth using the XmlHttp object
in VB6? Is it pretty much limited to a few parameters like name, rank, and
serial number, or can you move a list of stuff? It sounds just right for OP's
needs, but I'm curious about other situations. I suppose I could try moving more
data with a series of calls or something?

Nov 14 '06 #3

P: n/a
Steve Gerrard wrote:
"Dag Sunde" <me@dagsunde.comwrote in message
news:45***********************@news.wineasy.se...
>>
From vb, use the XmlHttp object or one of its siblings to POST
the data to this php-script on the server.

To view the high-scores, use the same principle. (Do it from php, and
when your vb client needs it, Use HTTP).

Dag, how much data is reasonable to move back and forth using the
XmlHttp object in VB6? Is it pretty much limited to a few parameters
like name, rank, and serial number, or can you move a list of stuff?
It sounds just right for OP's needs, but I'm curious about other
situations. I suppose I could try moving more data with a series of
calls or something?
If you use the "GET", it is limited to the max-length of the URL...

In Internet Explorer, this is 2,083 bytes, so I guess it is something
similar in the XMLHttp-object too.

If you use "POST" on the other hand, it is up to the server.
In IIS, the maximum number of bytes for one form variable is
approx. 102,399 bytes. To overcome this, you just send
several fields (variables) with the same name. IIS (ASP)
will then see them as an array you can loop thru.

I frequently send (POST) 500K via the xmlhttp object to an
ASP script running on IIS 5.0...

So if my POST'ed data look like this:
//PseudoJavascript
sData = "xmlData=" + escape("102399BytesOfData")
sData = sData + "&xmlData=" + escape("another102399BytesOfData")

xmlReq.open("POST", "Receiver.asp", true);
xmlReq.onreadystatechange = xmlSendBidCallback;
xmlReq.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded");
xmlReq.send( sData );

My Receiver.asp will assemble it like this:

//VBS fragment..
Dim xmlData
Dim i
for i = 1 to Request.Form("XmlData").Count
xmlData = xmlData & Request.Form("XmlData")(i)
next

--
Dag.

Nov 14 '06 #4

P: n/a
Um, wouldnt doing it like that give a major vulnerability so users can
cheat by going to http://mysite.com/highscores.php?score=23&name=me or
is that not how you meant :S.

Thanks, James.

Nov 14 '06 #5

P: n/a
Dag Sunde wrote:
Steve Gerrard wrote:
>"Dag Sunde" <me@dagsunde.comwrote in message
news:45***********************@news.wineasy.se. ..
>>>
From vb, use the XmlHttp object or one of its siblings to POST
the data to this php-script on the server.

To view the high-scores, use the same principle. (Do it from php,
and when your vb client needs it, Use HTTP).

Dag, how much data is reasonable to move back and forth using the
XmlHttp object in VB6? Is it pretty much limited to a few parameters
like name, rank, and serial number, or can you move a list of stuff?
It sounds just right for OP's needs, but I'm curious about other
situations. I suppose I could try moving more data with a series of
calls or something?

If you use the "GET", it is limited to the max-length of the URL...

In Internet Explorer, this is 2,083 bytes, so I guess it is something
similar in the XMLHttp-object too.

If you use "POST" on the other hand, it is up to the server.
In IIS, the maximum number of bytes for one form variable is
approx. 102,399 bytes. To overcome this, you just send
several fields (variables) with the same name. IIS (ASP)
will then see them as an array you can loop thru.

I frequently send (POST) 500K via the xmlhttp object to an
ASP script running on IIS 5.0...

So if my POST'ed data look like this:
//PseudoJavascript
sData = "xmlData=" + escape("102399BytesOfData")
sData = sData + "&xmlData=" + escape("another102399BytesOfData")

xmlReq.open("POST", "Receiver.asp", true);
xmlReq.onreadystatechange = xmlSendBidCallback;
xmlReq.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded");
xmlReq.send( sData );

My Receiver.asp will assemble it like this:

//VBS fragment..
Dim xmlData
Dim i
for i = 1 to Request.Form("XmlData").Count
xmlData = xmlData & Request.Form("XmlData")(i)
next
Forgot!

The response from these calls has no limit in its response...
(Except for timeout issues...)

So if you send a short request like "getHiscores.asp?limit=all",
and that results in a .responseText being 900K lonk, that
is not a problem, and no special consideration needs to be made.

--
Dag.
Nov 14 '06 #6

P: n/a
James54321 wrote:
Um, wouldnt doing it like that give a major vulnerability so users can
cheat by going to http://mysite.com/highscores.php?score=23&name=me or
is that not how you meant :S.
That can be avoided by letting the VB-App log in to the web-app first,
using the same principle and with a buildt-in MD5 or SHA1 encrypted
password first. Let the login return a sessionID, and then use that
id as a parameter in all subsequent calls.

--
Dag.

Nov 14 '06 #7

P: n/a

Dag Sunde wrote:
James54321 wrote:
Um, wouldnt doing it like that give a major vulnerability so users can
cheat by going to http://mysite.com/highscores.php?score=23&name=me or
is that not how you meant :S.

That can be avoided by letting the VB-App log in to the web-app first,
using the same principle and with a buildt-in MD5 or SHA1 encrypted
password first. Let the login return a sessionID, and then use that
id as a parameter in all subsequent calls.

--
Dag.
Won't doing that mean that I have to use the browser in VB or IE or
something like that meaning that the user will see whats going on?

Nov 14 '06 #8

P: n/a
James54321 wrote:
Dag Sunde wrote:
>James54321 wrote:
>>Um, wouldnt doing it like that give a major vulnerability so users
can cheat by going to
http://mysite.com/highscores.php?score=23&name=me or is that not
how you meant :S.

That can be avoided by letting the VB-App log in to the web-app
first, using the same principle and with a buildt-in MD5 or SHA1
encrypted password first. Let the login return a sessionID, and then
use that id as a parameter in all subsequent calls.

--
Dag.

Won't doing that mean that I have to use the browser in VB or IE or
something like that meaning that the user will see whats going on?
Nope...
:-)

Add "Microsoft XML, v3.0" (or higher) to references in a vb project.

Put a textbox and a command buttom on the form,
and set the textbox multiline property to true
and make it about an inch high.

Paste this code:

Option Explicit

Private xmlHttp As MSXML2.xmlHttp

Private Sub Command1_Click()

Set xmlHttp = New MSXML2.xmlHttp
xmlHttp.Open "POST", "http://dagsunde.com/pages/Reverse.asp", False
xmlHttp.SetRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
xmlHttp.Send "testString=" & Text1.Text

If xmlHttp.readyState = 4 Then
If xmlHttp.Status = "200" Then
Text1.Text = xmlHttp.responseXML.xml
Else
MsgBox "Something went wrong...", vbCritical, "ResponseXML
error"
End If
End If

End Sub
And run...
(My server will respond, and if you don't use a http-sniffer
or some other tool, you will not see whats going over the line).

--
Dag.
Nov 14 '06 #9

P: n/a

"Dag Sunde" <me@dagsunde.comwrote in message
news:45***********************@news.wineasy.se...
Dag Sunde wrote:
>Steve Gerrard wrote:
>>Dag, how much data is reasonable to move back and forth using the
XmlHttp object in VB6?

If you use the "GET", it is limited to the max-length of the URL...

If you use "POST" on the other hand, it is up to the server.
In IIS, the maximum number of bytes for one form variable is
approx. 102,399 bytes. To overcome this, you just send
several fields (variables) with the same name. IIS (ASP)
will then see them as an array you can loop thru.

I frequently send (POST) 500K via the xmlhttp object to an
ASP script running on IIS 5.0...

So if my POST'ed data look like this:
//PseudoJavascript
sData = "xmlData=" + escape("102399BytesOfData")
sData = sData + "&xmlData=" + escape("another102399BytesOfData")
The response from these calls has no limit in its response...
(Except for timeout issues...)

So if you send a short request like "getHiscores.asp?limit=all",
and that results in a .responseText being 900K lonk, that
is not a problem, and no special consideration needs to be made.
Ooh, I like it, 100K seems like decent amount to be able to post, and it looks
like sending multiple blocks is not much more work. I have been ducking away
from doing some of this, but the time is rapidly approaching. Thanks for the
answers and the examples and the "oh it is really no trouble at all" breezy
attitude. I'm sure there will be a little swearing along the way, but I feel
much more confident about making it work.

From the example in your other post:
<?xml version="1.0"?>
<root>
<rev_string>.uoyknahT</rev_string>
</root>
Nov 15 '06 #10

P: n/a
Steve Gerrard wrote:
"Dag Sunde" <me@dagsunde.comwrote in message
news:45***********************@news.wineasy.se...
<snipped/>
>>
So if you send a short request like "getHiscores.asp?limit=all",
and that results in a .responseText being 900K lonk, that
is not a problem, and no special consideration needs to be made.

Ooh, I like it, 100K seems like decent amount to be able to post, and
it looks like sending multiple blocks is not much more work. I have
been ducking away from doing some of this, but the time is rapidly
approaching. Thanks for the answers and the examples and the "oh it
is really no trouble at all" breezy attitude. I'm sure there will be
a little swearing along the way, but I feel much more confident about
making it work.
From the example in your other post:
<?xml version="1.0"?>
<root>
<rev_string>.uoyknahT</rev_string>
</root>
LOL

If you get into trouble, swear in my direction, and I'll try
to help you out...
That reminds me... Here is the Reverse.asp script:

<%@ Language=VBScript %>
<%Response.Buffer = True%>
<%
Response.ContentType = "text/xml"
Response.CacheControl = "Private"
Response.AddHeader "Cache-Control", "no-cache"

Dim testString
testString = Request.Form("testString")
testString = StrReverse(testString)

Response.Write( "<?xml version='1.0' encoding='iso-8859-1'?>" )
Response.Write( "<root>" & vbCrLf)
Response.Write( "<rev_string>" & testString & "</rev_string>" & vbCrLf )
Response.Write( "</root>" & vbCrLf)
Response.End()
%>

The reason for setting the contenttype to "text/xml" is to tell the
xmlhttp object that it will get xml-data back, and that it should
be able to fill its .responeXml attribute with a DOM tree.
Note that you then have to .Write well-formed xml back to it.

I often use plaintext instead:
Response.Write( testString )
Response.End()

In this case, the .responseXML will be empty (no valid xml),
but use the .responseText instead (on the client side).

--
Dag.
Nov 15 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.