• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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.
Thanks



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

Open in new window

0
CWS (haripriya)
Asked:
CWS (haripriya)
2 Solutions
 
segurahCommented:
Please, show a var_dump($row) .... What prints the line "echo $row['price'];"?
0
 
SPARC-DESIGNCommented:
try this to check if $row is filled with data:
if (is_array($row)) {
// your code...
}

Open in new window

0
 
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.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now