I want to save data from C++ to PHP and here is what I have
string cmd = "wget localhost/tem1.php?t=1&date=1&time=1";
system((const char*) cmd.c_str());
--2016-11-21 20:56:45-- http://localhost/tem1.php?t=1
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5 [text/html]
Saving to: 'tem1.php?t=1'
If this is on a Unix/Linux system, the reason is the ampersand
system executes your command by executing a shell
The system() library function uses fork(2) to create a child process that executes the shell command specified in command using execl(3) as follows:
execl("/bin/sh", "sh", "-c", command, (char *) 0);
system() returns after the command has been completed.
The shell interprets
& as putting the command into the background. To prevent this, you must wrap the argument with quotes
string cmd = "wget \"localhost/tem1.php?t=" + to_string(temperature) + "&date=" + date + "&time=" + time + "\"";
This tells the shell to leave the ampersand alone.