0

hi m writing a program n storing a values in session but one of them i.e of prie is not working . can any1 tel where m i wrong

$name=$_POST['P_list'];
	$quantity=$_POST['quantity'];
	
	
	$query= "SELECT product_name, unit_price FROM product WHERE product_name='$name'";
	$result=mysql_query($query);
	if ($result)
	{
	if (mysql_num_rows($result)==1)
	{
	$orders = mysql_fetch_assoc($result);
	$one_price=$orders['unit_price'];
	$_SESSION['product_name']=$orders['product_name'];
	$_SESSION['unit_price']=$orders['unit_price'];
	$_SESSION['quantity']=$quantity;
	
	$price=$one_price*$quantity;
	echo " the total amount to be paid for your given order will be:";
	echo "$price";
$_SESSION['price']=$price;
}

else
{
echo " No record found";
}
}
else
{echo "database failed";
}
3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by pzuurveen
0
$_SESSION['price']=$price;

In this line i store the value in session.but on the next page when i want to retrieve its value it gives the error.
next program is:

<?php 
session_start();
//print_r($_POST);
$name=$_SESSION['product_name'];
$c_name=$_SESSION['name'];
$price=$_SESSION['price'];
$quantity=$_SESSION['quantity'];

$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("pras2", $con) or die(mysql_error());


	$query="INSERT INTO `order`(customer_ID, product_id, quantity, price) VALUES ('$c_name', '$name', $quantity, $price)";
//die($query);

	$result=mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
	else
	{
	echo " Your order has been passed to admin for acceptance/rejection";
	}
	?>

while the error is

( ! ) Notice: Undefined index: quantity in C:\wamp\www\pras\order_entering.php on line 7

0

Apparantly 'quantity' may not have been set correctly, check for typos. Perhaps in your html.

Edited by pritaeas: n/a

0

change line 3 to

print_r($_SESSION);

and see...

or you can check and fall back to a defalt

if (isset($_SESSION['product_name'])
        $name=$_SESSION['product_name'];
else $name='Mr X';
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.