error: value="<? echo $row['Ename']; ?>"

Discussion in 'PHP' started by alanX, Jun 3, 2006.

  1. #1
    Hi:
    echo '<form method="post" action="edit.php">';
    echo '<table>';
    echo '<tr><td>Ename<input type="text" name="Ename"
    value="<? echo $row['Ename']; ?>" ></td>';
    echo '</tr>';
    echo '</table></form>';

    It show the error messge on --value="<? echo $row['Ename']; ?>"--
    (Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\delete.php on line 40)

    can anyone help me ?
     
    alanX, Jun 3, 2006 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd suggest replacing:
    echo '<tr><td>Ename<input type="text" name="Ename"
    value="<? echo $row['Ename']; ?>" ></td>';

    with:
    echo '<tr><td>Ename<input type="text" name="Ename" value="' . $row['Ename']; . '" ></td>';

    You're basically in the PHP parser, then trying to break in to the parser again (which does nothing) but then you break out straight after your echo, stopping the one and only parser, while you still have more to go. Hence, you never close the string you are echo'ing as far as PHP is concerned and so you get that error...
     
    TwistMyArm, Jun 3, 2006 IP
  3. alanX

    alanX Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much:
    i got it!
     
    alanX, Jun 3, 2006 IP
  4. mykoleary

    mykoleary Peon

    Messages:
    64
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not true at all. PHP is parsing the whole thing as one line until it finds a ;

    The issue is that he used single quotes to start and end the echo. He also usd single quotes in the $row variable.

    THAT closed the echo early.

    You need to escape single quotes used in a single quote encapsulated echo, and likewise for double quotes.
     
    mykoleary, Jun 3, 2006 IP
  5. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #5
    Another way to do it (maybe more simple).
    echo '<form method="post" action="edit.php">';
    echo '<table>';
    echo '<tr><td>Ename<input type="text" name="Ename"
    value=\"$row[Ename]\" ></td>';
    echo '</tr>';
    echo '</table></form>';
    
    PHP:
     
    goldensea80, Jun 6, 2006 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    goldensea80: that won't work, either, unfortunately.

    Your variable is in a string that uses single quotes (I don't quite know why you're trying to escape the double quotes around the $row[Ename]). Because of those single quotes, the variable won't be interpreted at all.

    mykoleary: you're right about those quotes. I think I need to upgrade my brain's PHP parser :(
     
    TwistMyArm, Jun 6, 2006 IP
  7. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #7
    Sorry, I made mistakes :D
    THis should work!
    echo '<form method="post" action="edit.php">';
    echo '<table>';
    echo "<tr><td>Ename<input type=\"text\" name=\"Ename\"
    value=\"$row[Ename]\" ></td>";
    echo '</tr>';
    echo '</table></form>';
    
    PHP:
     
    goldensea80, Jun 6, 2006 IP