Introduction
I am trying to make a API. Reading from the db works fine... Writing to it however is failing.
The weird part is when i copy the query error_log print-out and paste it into PHPMyAdmin, It added the object correctly.
Code
index.php
...
else if($tag == 'addIngredient'){
$name = $_POST['name'];
$cal = $_POST['cal'];
$fat = $_POST['fat'];
error_log("name=".$name." cal=".$cal."fat=".$fat);
if(!$db->addIngredient($name,$cal,$fat)){
$response["error"] = TRUE;
$response["error_msg"] = "addIngredient failed";
}
}
...
BDFunctions.php
...
public function addIngredient($name, $cal, $fat){
$query= "INSERT INTO `ingredient` (`name`, `cal`, `fat`) VALUES('".$name."', ".$cal.", ".$fat.");";
error_log($query);
$result = mysql_query($query);
if($result){return true;}
return false;
}
...
I get these print outs in my apache log:...
[Wed Apr 29 20:46:58 2015] [error] [client 192.168.1.9] name=testName cal=50fat=20 [Wed Apr 29 20:46:58 2015] [error] [client 192.168.1.9] INSERT INTO
ingredient
(name
,cal
,fat
) VALUES('testName', 50, 20);