Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING

Discussion in 'PHP' started by gw32, Jul 17, 2011.

  1. #1
    Could someone please help. I've been trying to see the error for hours and can't see the forest for the trees. I don't know what is wrong.


    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/shaskel1/public_html/abcdefdev/Test.php on line 17

    
    1. <?php
    2. require_once ('config.php');
    3. 
    4. echo "<Carousel>\n";
    5. 
    6. $query  = mysql_query("select a.im_name, b.name, a.description from images a, department b where a.dpt_id = '$pid';") or die(mysql_error());
    7. 
    8. /* $result = mysql_query($query);*/
    9. 
    10. while ($row = mysql_fetch_assoc($query)) {
    11. 
    12.   $path = "http://tegojewelers.com";
    13.
    14. /* the following echo's are supposed to be one line */
    15. /* <photo image="images/bridal.jpg" url="http://tegojewelers.com/Bridal/index.php" target="_self"><![CDATA[Bridal]]></photo> */
    16.
    17.   echo "<photo image='.$path.'/images/.$row['im_name'].";
    18.   	echo "url='.$path.'.$row['name']./index.php target='_self'>";
    19.  	echo "<![CDATA[.$row['description']]></photo>"; 
    20. }
    21. echo "</Carousel>\n";
    22. 
    23. mysql_close($dbh);
    24. 
    25. ?>
    
    Code (markup):
    Thank you
    Gordon
     
    gw32, Jul 17, 2011 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Your string concatenation syntax is wrong.

    Here's how:

    If you want to use double quote for echo.

    echo "<photo image=\"".$path."/images/".$row['im_name']."\"";
    echo "url=\"".$path.$row['name']."/index.php\" target=\"_self\">";
    echo "<![CDATA[".$row['description']."]></photo>";
    PHP:
    If you want to use single quote for echo. (I recommend using single quote for echo for html tags)

    echo '<photo image="'.$path.'/images/'.$row['im_name'].'"';
    echo 'url="'.$path.$row['name'].'/index.php" target="_self">';
    echo '<![CDATA['.$row['description'].']></photo>';
    PHP:

    -----------

    String concatenation is done using dot (.) operator, but you need to end the string part first before concatenating.

    echo "STRING PART".$variable."STRING PART".$variable;
    PHP:
    To concatenate 2 variables:

    echo $variable.$variable2."STRNG PART";
    PHP:
    If you echo statement uses double quote, and you want to display double quote, you need to escape it using backslash:

    echo "I am showing a double quote \" using backslash."; 
    PHP:
    or better if just use single quote for echo statement. You do not have to escape then.

    echo 'I am showing a double quote " using backslash.'; 
    PHP:
     
    ads2help, Jul 17, 2011 IP
  3. gw32

    gw32 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Works, no more errors.
    Just an empty string from database in while loop.
    SQL works in database.
     
    gw32, Jul 17, 2011 IP