cant show textarea notes when pulling from MySQL db

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alf8kitty
    New Member
    • Feb 2008
    • 6

    cant show textarea notes when pulling from MySQL db

    Hello,
    I have a form that allows a user to submit notes in a textarea.

    [HTML]<td><textarea name="Notes" value="" ROWS=3 COLS=35></textarea></td>[/HTML]

    The notes get sent to the MySQL database correctly when I check out the database entries.

    I have another form on the same page that pulls the notes field (along with some others) to display in another textarea. However, although the other fields pulled are displayed, the notes textarea remains empty. If I change the form's textarea to just text..it displays just the first word for each note stored in the database. Any ideas on how to get the full notes displayed?
    Thanks.

    The display form:
    <form>...
    <?
    $i=0;
    while ($i < $num) {
    $TimeSheetID=my sql_result($res ult, $i, "TimeSheetI D");
    $TaskDT=mysql_r esult($result,$ i,"TaskDT");
    $UserName=mysql _result($result ,$i,"UserName") ;
    $ClientName=mys ql_result($resu lt,$i,"LastName ");
    $HoursWorked=my sql_result($res ult,$i,"HoursWo rked");
    $Notes=mysql_re sult($result,$i ,"Notes");
    ?>

    <tr>
    <td><?php echo "<input name=TimeSheetI D type='text' value=$TimeShee tID id=TimeSheetID disabled='yes'/>";?></td>
    <td><?php echo "<input name=TaskDT type='text' value=$TaskDT id=TaskDT disabled='yes'/>";?></td>
    <td><?php echo "<input name=UserName type='text' value=$UserName id=UserName disabled='yes'/>";?></td>
    <td><?php echo "<input name=ClientName type='text' value=$ClientNa me id=ClientName disabled='yes'/>";?></td>
    <td><?php echo "<input name=HoursWorke d type='text' value=$HoursWor ked id=HoursWorked disabled='yes'/>";?></td>
    <td><?php echo "<input name=Notes type='text' value=$Notes id=Notes disabled='yes'/>";?></td>
    <td><?php echo "<input name=checkbox[] type='checkbox' value=$TimeShee tID id=checkbox[]>";?></td>
    </tr>

    <?php
    $i++;
    }
    ...</form>
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I dont quite understand your problem..

    Comment

    • alf8kitty
      New Member
      • Feb 2008
      • 6

      #3
      My issue is that i can see that the notes a user enters in the first form textarea get stored correctly to the database. But that when I try to pull that notes field from the database to display in another form..it either is blank or shows only the first word of all the text in the database (depending on if I am trying to display using a textarea or just text.

      My SQL query to get the data is:
      [PHP]//Connect to mysql server
      include 'config.php';
      include 'opendb.php';
      $query="SELECT ts.TimeSheetID, ts.TaskDT, e.UserName, c.LastName, ts.HoursWorked, ts.Notes
      FROM Emp_TimeSheet ts INNER JOIN Employee e ON ts.EmployeeID=e .EmployeeID
      INNER JOIN Client c ON ts.ClientID=c.C lientID
      WHERE e.EmployeeID='$ User' AND ts.TaskDT = '$Date'";

      $result=mysql_q uery($query);
      $num=mysql_numr ows($result);
      mysql_close();
      ?>[/PHP]


      Then to display the results of this SQL query in a new form i use:
      [PHP]<form id="deleteHours Form" name="deleteHou rsForm" method="post" action="deleteH ours-exec.php">

      <table border="1">
      <tr>
      <th>TimeSheetID </th>
      <th>TaskDT</th>
      <th>UserName</th>
      <th>ClientNam e</th>
      <th>HoursWorked </th>
      <th>Notes</th>
      <th>Delete</th>
      </tr>

      <?
      $i=0;
      while ($i < $num) {
      $TimeSheetID=my sql_result($res ult, $i, "TimeSheetI D");
      $TaskDT=mysql_r esult($result,$ i,"TaskDT");
      $UserName=mysql _result($result ,$i,"UserName") ;
      $ClientName=mys ql_result($resu lt,$i,"LastName ");
      $HoursWorked=my sql_result($res ult,$i,"HoursWo rked");
      $Notes=mysql_re sult($result,$i ,"Notes");
      ?>

      <tr>
      <td><?php echo "<input name=TimeSheetI D type='text' value=$TimeShee tID id=TimeSheetID disabled='yes'/>";?></td>
      <td><?php echo "<input name=TaskDT type='text' value=$TaskDT id=TaskDT disabled='yes'/>";?></td>
      <td><?php echo "<input name=UserName type='text' value=$UserName id=UserName disabled='yes'/>";?></td>
      <td><?php echo "<input name=ClientName type='text' value=$ClientNa me id=ClientName disabled='yes'/>";?></td>
      <td><?php echo "<input name=HoursWorke d type='text' value=$HoursWor ked id=HoursWorked disabled='yes'/>";?></td>
      <td><?php echo "<input name=Notes type='text' value=$Notes id=Notes disabled='yes'/>";?></td>
      <td><?php echo "<input name=checkbox[] type='checkbox' value=$TimeShee tID id=checkbox[]>";?></td>
      </tr>

      <?php
      $i++;
      }
      ?>
      <tr>
      <td colspan="7" align="right">< input name="delete" type="submit" id="delete" value="Delete"> </td>
      </tr>



      <?php
      echo "</table>";

      ?>
      </form>[/PHP]

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Originally posted by alf8kitty
        [PHP]<td><?php echo "<input name=TimeSheetI D type='text' value=$TimeShee tID id=TimeSheetID disabled='yes'/>";?></td>[/PHP]
        Your values are wrong when you're displaying them. Try:
        [PHP]<td><?php echo "<input name=TimeSheetI D type='text' value='".$TimeS heetID."' id=TimeSheetID disabled='yes'/>";?></td>[/PHP]

        Basically, I have just pulled your variable $TimeSheetID out of the text of the echo, making it a variable again and then surrounded it with ' '
        It is spaced out below as it is hard to read:
        value= ' " . $TimeSheetID . " '

        This might solve the problem.

        Comment

        • alf8kitty
          New Member
          • Feb 2008
          • 6

          #5
          cool! thanks very much! i am new to php and was just trying different ways to get variables to display so i didn't really know the proper syntax.

          Now that it works with text field - i tried to get it to work with with a textarea in the same way but failed...

          why does this not work:
          [PHP]<td><?php echo "<textarea name=Notes value='".$Notes ."' ROWS=3 COLS=35></textarea>";?></td>[/PHP]

          while this works:
          [PHP]<td><?php echo "<input name=Notes type='text' value='".$Notes ."' id=Notes disabled='yes'/>";?></td>[/PHP]

          thanks for your help!

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            The contents between <TEXTAREA ...> and </TEXTAREA> are used as the default value. So it should be:

            [PHP]<td><?php echo "<textarea name=Notes ROWS=3 COLS=35>".$Note s."</textarea>"; ?></td>[/PHP]

            Two pointers:
            1. Everytime you can't get a function to work (like textarea), just google it and try and see what attributes/parameters it has. In this case, textarea does not have a parameter "value".
            2. I suggest that you use lowercase for things like variables and tag names. Most things are case-sensitive, so you need to get a convention going for your code. I would write:
            [PHP]<td><?php echo "<textarea name=notes ROWS=3 COLS=35>".$note s."</textarea>"; ?></td>[/PHP] instead.

            Glad I could help ;)

            Comment

            Working...