The C++ part of the program will connect to the php and add a new row, with empty data instead of values.
Any help in pointing out where I am going wrong is most appreciated
<
<?php
error_reporting(E_ALL);
//connect
$dbh=mysql_connect("localhost","root","");
//select database
mysql_select_db("onlinedata",$dbh);
//add new user
$first=$_POST["firstname"];
$last=$_POST["lastname"];
$email=$_POST["email"];
mysql_query("INSERT INTO userinfo VALUES(NULL,\"".$first."\",\"".$last."\",\"".$email."\")",$dbh);
mysql_close($dbh);
?>
the C++ Code is as follows:
#include <string>
#include <windows.h>
#include <WinInet.h>
#include <fstream>
#include <iostream>
#include <tchar.h>
using namespace std;
int main()
{
HINTERNET IN hOpen; // Handle from InternetOpen()
hOpen = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
CHAR *szUrl="http://127.0.0.1/output.php"; // Full URL
DWORD dwSize;
CHAR szHead[] = "Accept: */*\r\n\r\n";
// CHAR * szHead="Content-Type: application/x-www-form-urlencoded";
VOID * szTemp[25];
HINTERNET hConnect;
FILE * pFile;
if ( !(hConnect = InternetOpenUrl ( hOpen, szUrl, szHead,lstrlen (szHead), INTERNET_FLAG_DONT_CACHE, 0)))
{
cout << "Error !" << endl;
return 0;
} cout<<GetLastError()<<endl;
static TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
static TCHAR frmdata[] = _T("firstname=John&lastname=Doe&email=charanders4@aol.com");
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST",_T(szUrl), NULL, NULL, NULL, 0, 1);
cout<<GetLastError()<<endl;
HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
cout<<GetLastError()<<endl;
}
>