I have a form that creats a json array from user input data.
I need to send that to a php curl file so that it can be sent to an ip address.
How do I populate the curl data array from that json file?


if remote expects json data, as it seems from the header set in the curl request, then just submit the json string as you are already doing. Use curl_error() if it seems that does not work:

You should also change this:

curl_setopt($post, CURLOPT_POST, count($data));


curl_setopt($post, CURLOPT_POST, TRUE);

It should not make much difference as probably PHP will cast the integer to TRUE and curl, once CURLOPT_POSTFIELDS are set, will send a POST request anyway.

Here's an example through a test API:


$data = ['msg' => 'hello', 'token' => mt_rand(1000, 9999)];
$data_string = json_encode($data);

$post = curl_init('http://jsonplaceholder.typicode.com/posts/');

curl_setopt($post, CURLOPT_VERBOSE, TRUE);
curl_setopt($post, CURLOPT_POST, FALSE);
curl_setopt($post, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($post, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

$result = curl_exec($post);


echo "RESULT:" . PHP_EOL . $result . PHP_EOL;

If the query does not return a result set, then the loop will not assign any value to $_SESSION and the print statement will show the previous value associated with that index: $_SESSION['status'].

I take the above for an example, but if $muser and $mypass are not set then the query will return all rows in the table.

So, if multiple rows are returned by the query, then $_SESSION will be overwritten and show the values of the last loop.

Right after session_start() add:

print print_r($_SESSION, TRUE);

This should tell you if you are carrying the value set by a previous step. Do the same after the loop. And see what you get.


Hello koneill,

What happens is that even though the information page has checks that data is filled in - the checkout file if a search crawl hits the page it sends blank info to the generic e-mail box.

Is this script checking on server side too? Since you are submitting a form, you can verify if the request method is POST. That should block random crawlers, as genuine robots usually do not send POST requests.

You could also add a csrf token to the session and to the form, and verify that the request matches the one saved in the session. This should block also intentionals submissions from remote.



Thank you Jim! Yes, that works fine and also counting the resulting array works fine.

The original query is not like in the above example: I was using FOUND_ROWS() in a PHP PDO class, to automatically extract the number of rows, but it was not working appropriately. So I started playing with an example table and added SQL_CALC_FOUND_ROWS too and came down with the above test.

Even by doing:


then FOUND_ROWS() should return 5, instead it returns 1. In practice, I do not understand why it does not output the expected result.

I just did a test on MariaDB 10.0.28 and MariaDB 10.1.19 and returns 5, as expected. My current instead is 10.0.29, so it may be a bug.


@Dani, yes, I added SQL_CALC_FOUND_ROWS just to test the query.



so, I'm playing a bit with MariaDB 10.0.29 and I cannot understand why FOUND_ROWS() keeps returning the 1 whatever happens to the latest select query. Here's my test:

Query OK, 0 rows affected
Time: 0.782s

> INSERT INTO `test` (`msg`) VALUES('apples'), ('oranges'), ('strawberries'), ('cherries'), ('random');
Query OK, 5 rows affected
Time: 0.180s

|   id | msg          |
|    1 | apples       |
|    2 | oranges      |
|    3 | strawberries |
|    4 | cherries     |
|    5 | random       |
5 rows in set
Time: 0.003s

|   FOUND_ROWS() |
|              1 |
1 row in set
Time: 0.002s

Expected result 5. The same happens with MyISAM engine.

Any clue why this happens? To avoid any possible backside issue, I have tested from a fresh connection through the command line client, but it does not seems to make difference.

The online test with MySQL 5.6, instead, returns 0, it is accessible here:

For the online test result I'm not sure it depends on SQLfiddle or it is MySQL 5.6.


Localhost? It seems a ramsonware, a virus that encrypts data and ask money to return the files back. If you are using Windows that's probably in your system, so it should not be related to the application code. The same can happen if the folder is shared in a local network and the virus is compromising all the files it can reach.

Good luck with that.


This line will raise an error and kill the execution:

trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);

If you want to use it, then you have to create a condition, something like this:

if( ! $result)
    trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);

Otherwise it will run at each execution.


I've also been getting a lot of sex spam. I wonder if someone got my email address off a database somewhere ^_^

Me too and they try to add my account to Hangouts, so I reply to add my "other" account instead, which is the email address of a previous spammer. When they insist, I reply with Siri's quotes, random tweets, youtube videos. Last time, the correspondence continued for a week before they gave up.