what is wrong with this code?

Posted on 2009-04-21
Last Modified: 2012-05-06
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

Question by:Haripriya Sathiish
    LVL 6

    Accepted Solution

    Please, show a var_dump($row) .... What prints the line "echo $row['price'];"?
    LVL 3

    Assisted Solution

    try this to check if $row is filled with data:
    if (is_array($row)) {
    // your code...

    Open in new window

    LVL 16

    Author Comment

    by:Haripriya Sathiish
    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.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now