Writing data to a html textarea via php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fredb
    New Member
    • Feb 2007
    • 10

    Writing data to a html textarea via php

    I am trying to write data from my database to a html textarea. I can write the data with the php print function. Below is the code.

    Any help you can offer is greatly appreciated.

    Thanks,
    Fred Bernstein

    <?php
    $sqlquery = "SELECT * FROM dbo.TBL_FACULTY _INFORMATION WHERE ID_NUM = $id_num";

    $fi_tbl = odbc_exec($sqlc onnect, $sqlquery);
    if (!$fi_tbl) {
    exit("Error in SQL 1");
    }

    odbc_fetch_row( $fi_tbl);
    $ln = odbc_result($fi _tbl,"Last_Name ");
    $fn = odbc_result($fi _tbl,"First_Nam e");
    $mn = odbc_result($fi _tbl,"Middle_Na me");
    $notes = odbc_result($fi _tbl, "NOTES");

    print "notes = $notes";
    print "<p>fn = $fn</p>";
    print "<p>ln = $ln</p>";

    odbc_close($sql connect);
    ?>

    <form id="form1" name="form1" method="post" action="">
    <textarea name="textarea" cols="75" rows="8" id="<?php echo $notes ?>"></textarea>
    </form>
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    This is incorrect, you are trying to write in id attribute
    [HTML]<textarea name="textarea" cols="75" rows="8" id="<?php echo $notes ?>"></textarea>[/HTML]

    for most of the html form elements:
    [HTML]<input type="text" name="element_n ame" value="<? echo $var_name; ?>" />[/HTML]

    If you want to Print your PHP output variables in a HTML textarea, you can't use the ordianary way of other HTML form elements.

    [HTML]<textarea name="textarea" cols="75" rows="8" id="id_goes_her e"><?php echo $notes ?></textarea>[/HTML]

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Please note that I did not check your PHP Script to retrive Table values.
      if there is Error in that please POST the errors here with your DB script.
      ;)

      Comment

      • fredb
        New Member
        • Feb 2007
        • 10

        #4
        Originally posted by ajaxrand
        This is incorrect, you are trying to write in id attribute
        [HTML]<textarea name="textarea" cols="75" rows="8" id="<?php echo $notes ?>"></textarea>[/HTML]

        for most of the html form elements:
        [HTML]<input type="text" name="element_n ame" value="<? echo $var_name; ?>" />[/HTML]

        If you want to Print your PHP output variables in a HTML textarea, you can't use the ordianary way of other HTML form elements.

        [HTML]<textarea name="textarea" cols="75" rows="8" id="id_goes_her e"><?php echo $notes ?></textarea>[/HTML]
        Your solution worked perfectly. Thank you very much for your help.

        Comment

        • rpjd
          New Member
          • Mar 2007
          • 25

          #5
          Originally posted by fredb
          Your solution worked perfectly. Thank you very much for your help.
          I am trying to do more or less the same thing, I think. I have a html select option which calls an onclick() function. The javascript calls a file.php which in turn executes a database query retieving a value called $value. I am trying to then send the $value variable back to a text field within the HTML via javascipt. I have tried using several methods such this one, but haven't found anything that works as yet.
          [code]
          <input type="text" name="variable" value="<? echo $value ?>"/>
          [code]
          but all I get is a text field with php code. Is there a way of doing this?

          RPJD :)

          Comment

          • TheMadMidget
            New Member
            • Oct 2006
            • 98

            #6
            Code:
            <input type="text" name="variable" value="<?php echo $value; ?>"/>

            Comment

            Working...