Wininet Trouble...

Ok i been battling with this script. it uses Wininet API to send data to a php server,

The thing is, i am using a GET statement, it is supposed to get the data and send to the server and then the php script should save to the database

code looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#define _WIN32_WINNT 0x600

#include <stdio.h>
#include <windows.h>
#include <wininet.h>

#pragma comment (lib,"wininet")

int main()
{
	HINTERNET hInternet = InternetOpen("AddyApp",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
	HINTERNET hSession = InternetConnect(hInternet,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,0);
	HINTERNET hReq = HttpOpenRequest(hSession,"GET","/wininettest/server.php",NULL,NULL,NULL,0,0);

	char name[50] = "Kazo";
	char num[50] = "0809xxxxxxxxxxxx";

	char pBuf[1024]="name=%s&num=%s";
	HttpSendRequest(hReq,NULL,0,pBuf,strlen(pBuf));

DWORD dwAvailable,dwBytesRead;
char pOutBuf[1024];
char* pTempBuf=pOutBuf;
while(InternetQueryDataAvailable(hReq,&dwAvailable,0,0) && dwAvailable != 0)
{
DWORD dwBytesRead;
InternetReadFile(hReq,pTempBuf,dwAvailable,&dwBytesRead);
pTempBuf += dwBytesRead;
}
	InternetCloseHandle(hReq);
		InternetCloseHandle(hSession);
			InternetCloseHandle(hInternet);

			printf("Sent Successfully \n");
			system("pause");
	}


and the php code that sends to database looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'namedb';

$con = mysqli_connect($host,$user,$pass,$db) or die('Cannot connect');
mysqli_select_db($con,$db);
// get info

$name = $_GET['name'];
$num = $_GET['num'];

$sql = "INSERT INTO `peoplebase2`(`name`, `num`) VALUES ('".$name."', '".$num."')";

mysqli_query($con,$sql) or die ('Query Failed');

mysqli_close($con);

echo '1 Row Entered';
?>



What is really wrong?
Last edited on
Topic archived. No new replies allowed.