Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Error using echo

    Why do I get:
    PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
    ... when using echo "Small - $data['sizes']";

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    The array is messing it up ...

    Do this ... with brackets ...

    echo "Small - {$data['sizes']}";

    Or this ... appending string ...

    echo "Small - ".$data['sizes'];

    Or this .. changing array value to a variable ...

    $size=$data['sizes'];
    echo "Small - $size";


    .

  • Users who have thanked mlseim for this post:

    Democrazy (09-12-2011)

  • #3
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Ah har yes, makes sense! I used the first one. Thank you for your help.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Democrazy View Post
    Why do I get:

    ... when using echo "Small - $data['sizes']";
    I've already replied to this in your other topic.

    If you read the reply I left for you there you will see I recommended you look at the link in my signature about quotes and I also explained that you should not use single quotes for the array key inside double quotes.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by mlseim View Post
    The array is messing it up ...

    Do this ... with brackets ...

    echo "Small - {$data['sizes']}";

    Or this ... appending string ...

    echo "Small - ".$data['sizes'];

    Or this .. changing array value to a variable ...

    $size=$data['sizes'];
    echo "Small - $size";


    .
    Or the easier way - delete the single quotes:

    echo "Small - $data[sizes]";
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hmmm it does work, and tangoforce's suggestion is what I tried myself, but it won't work in the context I need it (which you will see why). I should of used this context in my OP. Appoligies, next time..

    Anyway, I then tried to use your second suggestion mlseim, but it failed:

    else {echo "Small - "}.$data['sizes'];

    I also tried this:

    else {echo "Small - ".$data['sizes']};
    Last edited by Democrazy; 09-12-2011 at 05:34 PM.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Democrazy View Post
    I then tried to use the second suggestion, but it failed:

    else {echo "Small - "}.$data['sizes'];
    Not that you're listening to anything I say.. but here you go:

    else {echo "Small - " .$data['sizes']};

    Also unless you have a variable inside those double quotes swap them for single quotes.

    READ THE QUOTES TOPIC IN MY SIGNATURE for the last time. You might actually learn something
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    I am new get over it, I can't remember everything in one go, and I have been listening to you. I even saved your lines from previous posts into a text file.

  • #9
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    else {echo "Small - " .$data['sizes']};
    Does not work.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    But why open two topics about the same issue? - I had already explained this to you in the last one.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hey you know what! It is working. PHP was giving me some bizarre error about an error being on line 79, but the document only went upto line 78... so I performed undo to the last time the page was working and applied your code and it worked.

    That is STRANGE!

  • #12
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    But why open two topics about the same issue? - I had already explained this to you in the last one.
    Which other topic?

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Probably missing a ; somewhere or a } in the wrong place that you hadn't noticed. Happens to all of us.

    Glad its working but now its time for you to brush up on your knowledge of quote marks before you get yourself into murkier water
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #14
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Yeah, I am learning slowly.

    If you were to tell me I'd understand basic PHP 2 weeks ago I would of laughed.

    4 weeks ago I was convinced MySQL sucked and Python and flat-files was the answer to databases. LOL


    Python is however, an AWESOME language and I have high respects for it.
    Flat files are cool too, but for application configuration files like in Linux.

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Flat files are just wrong for a web based system IMO. Sure, it saves you having to learn to use mysql which always sounds daunting but flat files are not thread safe. That means two instances of your php script could access and read/write information to the same part of the file at the same time leading to data corruption. This is why using a thread safe database like mysql is superior to flat files.

    Additionally with flat files you've got to write your own functions for finding data, updating it etc. Pain in the grass if you ask me.. I should know when I was writing apps in delphi rather than use a DB I was using ini files. 3 years later the application still isn't finished due to all of the file code needed.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •