what is wrong with this code?

The below code does not display the price value.

With line : $msg = 'Your Price is £' . $price;
when I echo the value of $msg, it displays like this: Your Price is £

Whereas With line : $msg = 'Your Price is £' . $row['price'];
when I echo $msg, it displays the price. Your Price is £64

what is wrong with the below code? It was working perfect few minutes back when the code was in the same php page. Now I wanted to use AJAX so I copied this code in a seperate page.

I want to know why this happens.

Any help or suggestion is appreciated.

if ($row)
			//item price
			echo "<br>row=";
			$price = $row['price'];
			echo $row['price'];
			//item id
			$id = $row['id'];
			//write id & price to session
			$_SESSION['price'] = $price;
			$_SESSION['id'] = $id;
			$_SESSION['description'] = $description;
			$_SESSION['colors'] = $colours;
			$msg = 'Your Price is &pound;' . $price;
echo $msg;

Open in new window

LVL 16
CWS (haripriya)Asked:
Who is Participating?
segurahConnect With a Mentor Commented:
Please, show a var_dump($row) .... What prints the line "echo $row['price'];"?
SPARC-DESIGNConnect With a Mentor Commented:
try this to check if $row is filled with data:
if (is_array($row)) {
// your code...

Open in new window

CWS (haripriya)Author Commented:
Some where in my php page where this ajax function is called, $price=' ' is set to empty. I wonder how this conflicts the value comes from ajax. I tried $price1 instead of $price, surprisingly the value of $price1 gets displayed. I would like to leave this issue with this.

Thanks for your time.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.