Forum Moderators: coopster
I've tried everything but I think my logic's a little wrong - can I just run this by you please, and I would appreciate any comments.
I have userid and comments that I want to post. Now these 2 variables come from a form which is laid out in a table of two columns (userid and comments) on my editing page.
The table is lots of <textarea>s which display userid and comments already in the database. I want to edit only some of the <textarea>s each time I visit the editing page, and then they should be updated.
//check for posted data
if (isset($_POST['submit'])) {
$userid=$_POST['userid'];
$comments=$_POST['comments'];
foreach($userid as $userid){
foreach($comments as $comments){
echo"$comments $userid<br />";
}
}
Now this is obviously wrong because although the comments process correctly, the userid is the same for each line.
Any poiners? Any help gratefully received.
<form id="thisfile.php" method="post"
action="<?php $_SERVER['PHP_SELF']; ?>">
<table>
<?php
while($i<$num){
$userid=mysql_result($result,$i,"userid");
$comments=mysql_result($result,$i,"comments");
//display this data
echo"<tr><td>
<input type=\"hidden\" name=\"userid\" value=\"$userid\">
<textarea rows=\"5\" cols=\"100\" name=\"comments[]\">$comments</textarea>
</td></tr>";
$i++;
}
?>
</table>
Any ideas?
while($i<$num)
{
<textarea rows=\"5\" cols=\"100\" name=\"comments".$i."\">$comments</textarea>
}
This will create you $i textareas
Where you proccess your form data you can do a simple loop through all the names to see which one was submitted and maniluate that field only
As an alternate mehtod
you can assign each textarea field to a seperate form
There pass some unique var as a hidden field so as you know which textarea is being submitted