Why is the first section outputting data nd the 2nd is not?

Discussion in 'PHP' started by tyler_durden, Apr 2, 2007.

  1. #1
    I'm learning php and html on the fly, and I am stuck with the code below. The subject row outputs the "value=subject" from the database, but the Message row does not outout the "value=comment". I can echo the $comment variable, so it is there, but not in the Text Area field. I'm sure it's a simple coding error.


    //-- Subject Row --
    echo "<TR><TD>
    <B>$ndx_eve_name</B></TD><TD>
    <IMG SRC=\"q.gif\" ALT=\"$ndx_eve_desc\" title=\"$ndx_eve_desc\">&nbsp;&nbsp;&nbsp;
    [COLOR="Red"]<INPUT TYPE=SUBJECT SIZE=40 NAME=\"subject\" value=\"$subject\">[/COLOR]
    </TD><TD></TD></TR>";
    
    // -- Message Row --
    echo "<TR><TD>
    <B>$ndx_msg</B>&nbsp;&nbsp;&nbsp;<IMG SRC=\"q.gif\" ALT=\"$ndx_body\" title=\"$ndx_body\"></TD><TD></TD>
    <TD><INPUT TYPE=submit VALUE=$ndx_save>&nbsp;&nbsp;&nbsp;
    <IMG SRC=\"q.gif\" ALT=\"$ndx_clk&nbsp;$ndx_save&nbsp;$ndx_str\" title=\"$ndx_clk&nbsp;$ndx_save&nbsp;$ndx_str\">
    </TD></TR>
    <TR><TD COLSPAN=\"3\">
    [COLOR="red"]<TEXTAREA value=\"$comment\" NAME=\"comment\" COLS=\"70\" WRAP=hard ROWS=\"10\"></TEXTAREA>[/COLOR]
    </TD></TR>
    Code (markup):
     
    tyler_durden, Apr 2, 2007 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    You shouldnt do HTML and PHP in this way as its messy.
    Some people chose to do it like this but i just think it creates more work than is necessary.
    Do this:
    ?>
    //-- Subject Row --
    <TR><TD>
    <B>$ndx_eve_name</B></TD><TD>
    <IMG SRC="q.gif" ALT="$ndx_eve_desc" title="$ndx_eve_desc">&nbsp;&nbsp;&nbsp;
    <INPUT TYPE=SUBJECT SIZE=40 NAME="subject" value="<?php echo $subject; ?>">
    </TD><TD></TD></TR>";
    
    // -- Message Row --
    <TR><TD>
    <B>$ndx_msg</B>&nbsp;&nbsp;&nbsp;<IMG SRC="q.gif" ALT="$ndx_body" title="$ndx_body"></TD><TD></TD>
    <TD><INPUT TYPE=submit VALUE=$ndx_save>&nbsp;&nbsp;&nbsp;
    <IMG SRC="q.gif" ALT="$ndx_clk&nbsp;$ndx_save&nbsp;$ndx_str" title="$ndx_clk&nbsp;$ndx_save&nbsp;$ndx_str">
    </TD></TR>
    <TR><TD COLSPAN="3">
    <TEXTAREA value="<?php echo $comment; ?>" NAME="comment" COLS="70" WRAP=hard ROWS="10"></TEXTAREA>
    </TD></TR>
    <?php
    //more php code
    Code (markup):
     
    papa_face, Apr 2, 2007 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    papa_face is right about making your code clean, but it still doesn't answer your question.

    The biggest problem is that a textarea does not have a value property. The 'value' goes between the opening and closing textarea tags. So, based on papa_face's code, you want to change:
    
    <TEXTAREA value="<?php echo $comment; ?>" NAME="comment" COLS="70" WRAP=hard ROWS="10"></TEXTAREA>
    
    PHP:
    to:
    
    <TEXTAREA NAME="comment" COLS="70" WRAP=hard ROWS="10"><?php echo $comment; ?></TEXTAREA>
    
    PHP:
    Hope that helps.
     
    TwistMyArm, Apr 2, 2007 IP
  4. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you both for the suggestions - fortunately I did not originally code this, but I probably should clean it up!
     
    tyler_durden, Apr 2, 2007 IP
  5. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #5
    Glad TwistMyArm offered the solution. I kinda forgot about the actual problem you were having when I posted lol.
     
    papa_face, Apr 2, 2007 IP