Prototype framework - new JSON AJAX problem

This is a different problem than the previous one which was resolved. Thanks so much for your help.

In this case, I’m sending an AJAX request using Prototype to the database on localhost to create a new database entry. This is the key part of the JavaScript page that sends that AJAX request (remember its with Prototype framework)

       new Ajax.Request('../ajax/addtofridge.php',
	  method: 'post',
  	  parameters: passme=strFoodToAdd

passme is a previously undefined or initialized variable (do i need to do that before using it here?). strFoodToAdd contains a JSON string that is exactly:

{“food”:“Canned Cut Asparagus”,“brand”:“Selection”,“ftype”:“Fruit & Vegetables”,“servamt”:“1/2 cup”,“ss”:“125mL”,“cal”:25,“fat”:0.3,“sat”:0,“trans”:0,“chol”:0,“sod”:260,“carb”:4,“fib”:2,“sug”:2,“pro”:2}

The php page that is requested, addtofridge.php, has only the following code:


	extract( $_POST );

	$objFoodToAdd = json_decode($passme);
	$food 				= "food";
	$brand 				= "brand";
	$ftype				= $objFoodToAdd->ftype;
	$servamt 			= $objFoodToAdd->{'servamt'};	

        @ $db = mysqli_connect('localhost', 'root', '', 'mealchamp');
	$query = "INSERT INTO gloosemo_persfood (food, brand, ftype, servamt) VALUES ('" . $food . "', '" . $brand . "', '" . $ftype . "', '" . $servamt . "')";

	$result = mysqli_query($db, $query);


PROBLEM: the database table does not update properly. the two values that are simply strings ($food and $brand) DO update properly, but $ftype and $servamt do not. what am i doing wrong with these variables? is my object notation wrong? or did i not set up passme correctly on either page?

help is appreciated, thanks

I’d try this and see what you getting:

$query = “INSERT INTO gloosemo_persfood (food, brand, ftype, servamt) VALUES ('” . $food . “', '” . $brand . “', '” . $ftype . “', '” . $servamt . “')”;

echo $query;

//$result = mysqli_query($db, $query);