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";
}

Recommended Answers

All 4 Replies

No error visible in this part. What exactly is not working? Please no chat speak, try full sentences.

$_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

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

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';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.