By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,013 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

cant show textarea notes when pulling from MySQL db

P: 6
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=mysql_result($result, $i, "TimeSheetID");
$TaskDT=mysql_result($result,$i,"TaskDT");
$UserName=mysql_result($result,$i,"UserName");
$ClientName=mysql_result($result,$i,"LastName");
$HoursWorked=mysql_result($result,$i,"HoursWorked" );
$Notes=mysql_result($result,$i,"Notes");
?>

<tr>
<td><?php echo "<input name=TimeSheetID type='text' value=$TimeSheetID 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=$ClientName id=ClientName disabled='yes'/>";?></td>
<td><?php echo "<input name=HoursWorked type='text' value=$HoursWorked 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=$TimeSheetID id=checkbox[]>";?></td>
</tr>

<?php
$i++;
}
...</form>
Feb 25 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
I dont quite understand your problem..
Feb 25 '08 #2

P: 6
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.ClientID
WHERE e.EmployeeID='$User' AND ts.TaskDT = '$Date'";

$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>[/PHP]


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

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

<?
$i=0;
while ($i < $num) {
$TimeSheetID=mysql_result($result, $i, "TimeSheetID");
$TaskDT=mysql_result($result,$i,"TaskDT");
$UserName=mysql_result($result,$i,"UserName");
$ClientName=mysql_result($result,$i,"LastName");
$HoursWorked=mysql_result($result,$i,"HoursWorked" );
$Notes=mysql_result($result,$i,"Notes");
?>

<tr>
<td><?php echo "<input name=TimeSheetID type='text' value=$TimeSheetID 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=$ClientName id=ClientName disabled='yes'/>";?></td>
<td><?php echo "<input name=HoursWorked type='text' value=$HoursWorked 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=$TimeSheetID 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]
Feb 25 '08 #3

TheServant
Expert 100+
P: 1,168
[PHP]<td><?php echo "<input name=TimeSheetID type='text' value=$TimeSheetID id=TimeSheetID disabled='yes'/>";?></td>[/PHP]
Your values are wrong when you're displaying them. Try:
[PHP]<td><?php echo "<input name=TimeSheetID type='text' value='".$TimeSheetID."' 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.
Feb 25 '08 #4

P: 6
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!
Feb 25 '08 #5

TheServant
Expert 100+
P: 1,168
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>".$Notes."</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>".$notes."</textarea>"; ?></td>[/PHP] instead.

Glad I could help ;)
Feb 26 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.