PHP: Cant get variable value - Please help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

PHP: Cant get variable value - Please help

Post by Bbob »

Hi

In this code, whenever I "keyup" the #qty I keep getting a 0 value for $price. Its driving me crazy, I mean the variable is on top and it cant read it ARGGHH! :cry: :x :banghead: :banghead: :banghead:

Heres my code :)

json.js

Code: Select all

  
$(document).ready
(
	function()
	{
		//GET PRICE
		var name = $('#itemname').val();
	
		$.post('script/php/createpo.php',
		{
				itemname: name
		},
		function(a)
		{
			$('#unitprice').html(a.price).show();
		}, "json");		
		
		$('#itemname').change(function()
		{
			var name = $('#itemname').val();
					
			$.post('script/php/createpo.php',
			{
				itemname: name
			},
			function(a)
			{
				$('#unitprice').html(a.price).show();
			}, "json");
		});
		
		//GET QTY
		$('#qty').keyup(function()
		{
			var qty = $('#qty').val();
			
			$.post('script/php/createpo.php',
			{ 
				qty: qty 
			},
			function(b)
			{
				$('#error').html(b.error).show();
				$('#amount').html(b.total).show();
			}, "json");
		});
	}
);
php

Code: Select all

<?php
	

	require("../../../require/connect.php");
	
	$id  = $_POST['itemname'];
	
	//GET PRICE OF $ID 
	$getprice = mysql_query("SELECT price
							 FROM pricelist
							 WHERE itemid = '$id'");
	
	$row = mysql_fetch_assoc($getprice);
	
	
	$price = $row['price'];
	$echo['price'] = $price; 
	
	//GET QTY
	$qty = $_POST['qty'];
	
	if(!is_numeric($qty))
	{
		$echo['error'] = "Qty must be numeric"; 
	}
	
	elseif($qty < 100)
	{
	   $echo['error'] = "Qty must be above 100"; 
	}
	
	else
	{
		$echo['error'] = " ";
	}
	
	$total = $qty * $price;
	$echo['total'] = $total;
	
	/*
	  ARRAY
		$echo
	  VALUES
		price
		error
		total
	*/
	
	echo json_encode($echo);
	
?>
Post Reply