stardust Posted August 8, 2009 Share Posted August 8, 2009 Hi, OK, it's all about a game I'm creating in VB6, and I want to give the player the possibility to submit from within the application his/her score on internet. What I have so far is a MySQL setup database on my server with a table named 'scores'. I also have the attached PHP code. When I run it from the browser everything seems to work fine and one record is added to the table: <? $username="******"; $password="******"; $database="******"; $name="John Smith"; $score=10234; // Connect to database mysql_connect ("***************" , $username, $password) or die ("Cannot connect to database" ); mysql_select_db($database) or die ("Cannot open database" ); mysql_query ("INSERT INTO scores (Name,Score) VALUES ('$name','$score')"); mysql_close(); ?> However, the problem occurs when I try to run it from VB6 application with the following code: Option Explicit Private Sub cmdSubmitScore_Click() Dim strResponse As String Dim playerName As String Dim Score As Long playerName = "John Smith" Score = 1548 strResponse = Inet1.OpenURL("http://www.mywebsite.com/submit_score.php?name=" & playerName & "&score=" & Score) If InStr(1, strResponse, "score submitted!", vbTextCompare) > 0 Then MsgBox "Your score has been submitted!", vbInformation Else MsgBox "Error submitting score!", vbExclamation End If End Sub I keep getting the "Error submitting score!" I'm not very good at PHP syntax nor at using Inet control, so all I can do now is to wait for your kind help... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/ Share on other sites More sharing options...
trq Posted August 8, 2009 Share Posted August 8, 2009 If your php works fine when executed from your browser then the problem isn't php. having said that however, your php script does not send 'score submitted!' as any response. Maybe you want to fix that. Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893497 Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 I've never used VB but I can tell what you're mistakes are. Your VB script is calling the following url http://www.mywebsite.com/submit_score.php?name=some_name_here&score=some_score_here Now in submit_score.php you are not retrieving the variables set with in the url.To retrieve name and score url variables you'll need to use the $_GET superglobal, like so $_GET['name'] and $_GET['score']. You'll want to use these variables within your query. Like so if(isset($_GET['name'], $_GET['score'])) { $name = mysql_real_escape_string($_GET['name']); $score = (int) $_GET['score']; $result = mysql_query ("INSERT INTO scores (Name,Score) VALUES ('$name','$score')"); } Now your script will insert the values your VB script pass to score_submit.php However there is one more isse The VB script is expecting some respone from the script. It is expecting the string score submitted! to be returned. To do this change $result = mysql_query ("INSERT INTO scores (Name,Score) VALUES ('$name','$score')"); to $result = mysql_query ("INSERT INTO scores (Name,Score) VALUES ('$name','$score')"); if($result) echo 'score submitted!'; Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893539 Share on other sites More sharing options...
stardust Posted August 8, 2009 Author Share Posted August 8, 2009 throp, wildteen88, thank you for your reply. wildteen88, this is how my PHP code looks after your suggestions: <? $username="******"; $password="******"; $database="******"; //$name="John Smith"; //$score=10234; // Connect to database mysql_connect ("***************" , $username, $password) or die ("Cannot connect to database" ); mysql_select_db($database) or die ("Cannot open database" ); if(isset($_GET['name'], $_GET['score'])) { $name = mysql_real_escape_string($_GET['name']); $score = (int) $_GET['score']; $result = mysql_query ("INSERT INTO scores (Name,Score) VALUES ('$name','$score')"); } if($result) echo 'score submitted!'; mysql_close(); ?> Unfortunately, it's not working for me - the same old problem (and when run from the browser no record is added to the table. Could you please review the code to see if there's any problem with it? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893577 Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 When running your script you need to be going to the following url mywebsite.com/submit_score.php?name=some_name_here&score=some_score_here In order for a record to be inserted into the database. Change this in your VB script MsgBox "Error submitting score!", vbExclamation To MsgBox "Error submitting score! " & vbNewLine & "Response Text = strResponse" & strResponse, vbExclamation What does your VB script output now? Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893584 Share on other sites More sharing options...
stardust Posted August 8, 2009 Author Share Posted August 8, 2009 wildteen88, thank you very much for your great help. Everything is working fine now. Before it wasn't working because I removed something from the VB script and forgot to put it back - sorry for the false alarm. As you see I added 3 more variables: city, country and date. I made some changes to the PHP script, and all is working fine except the date variable (it declared as Date in the database but displays a string of zeros). <? $username="******"; $password="******"; $database="******"; // Connect to database mysql_connect ("***************" , $username, $password) or die ("Cannot connect to database" ); mysql_select_db($database) or die ("Cannot open database" ); if(isset($_GET['name'], $_GET['score'])) { $name = mysql_real_escape_string($_GET['name']); $city = mysql_real_escape_string($_GET['city']); $country = mysql_real_escape_string($_GET['country']); $score = (int) $_GET['score']; $date = mysql_real_escape_string($_GET['date']); $result = mysql_query ("INSERT INTO scores (Name,City,Country,Score,Date) VALUES ('$name','$city','$country','$score','$date')"); } if($result) echo 'score submitted!'; mysql_close(); ?> I also tried to changed the line: if(isset($_GET['name'], $_GET['score'])) to: if(isset($_GET['name'], ($_GET['city'],($_GET['country'],$_GET['score'],($_GET['date'])) but it didn't work so I left it as it is. I will be thankful if you could review the PHP script once again. Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893640 Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 I also tried to changed the line: if(isset($_GET['name'], $_GET['score'])) to: if(isset($_GET['name'], ($_GET['city'],($_GET['country'],$_GET['score'],($_GET['date'])) but it didn't work so I left it as it is. Should be if(isset($_GET['name'], $_GET['city'], $_GET['country'], $_GET['score'], $_GET['date'])) ... except the date variable (it declared as Date in the database but displays a string of zeros). What is the format of your date? When setting the data type to date for your date column MySQL is expecting the following format yyyy-mm-dd. Or if its datetime then the expected format is yyyy-mm-dd hh:mm:ss Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893643 Share on other sites More sharing options...
stardust Posted August 8, 2009 Author Share Posted August 8, 2009 I made the changes according to your instructions and finally everything is working like a magic. I might come with more questions regarding Inputting the data using HTML pages. Thanks a lot, wildteen88 for your great help. Quote Link to comment https://forums.phpfreaks.com/topic/169324-solved-php-vb6-help-needed/#findComment-893657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.