Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-01-2011, 11:13 PM   PM User | #1
gloosemo
New Coder

 
Join Date: Mar 2011
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
gloosemo is an unknown quantity at this point
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)

Code:
       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:

Code:
<?php

	extract( $_POST );
	session_start();

	$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
gloosemo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:29 AM.


Advertisement
Log in to turn off these ads.