I am getting a string using curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close ($ch);
and then I am updating a table in mySQL with that string:
$query = "UPDATE $table SET code='$result' WHERE id=$id";
$result = mysql_query($query)or die("Update query failed : " . mysql_error());
problem is the column is blank after the update. If I echo $result I see the string in the browser so I know it is arriving from curl and if I type the string in myself (instead of using the curl $result) then it inserts fine as well. I’ve tried every combo of string cleaning I can think of:
mysql_real_escape_string(htmlentities($result));
But still no dice. Is there anything special about the string curl returns that would prevent it from being inserted into mySQL?
btw, the string it returns looks like this: ABC*DEF*12345ABC
SOLUTION
Following the advice given it turned out the curl $result had a \n at the head which I was not able to see until I echo’d the $query. I was able to quickly fix it with a str_replace() to remove the \n.
I would modify the code slightly to the following to add some debug:
Make sure that the query looks correct and attempt to run it from the MySQL console or phpmyadmin, workbench, etc and check to see if you get any errors when running it that way. When you run it from the console look very carefully to see if any warnings are generated on update.