i'm very new to php and i'm having trouble with getting a form to be made in a loop. i've played around with the code and so it may be in shambles right now, but i think you'll get the idea from this
while($obj=mysql_fetch_object($result))
{
//other code that's not part of the problem
echo "<td>
<font color=\"white\" size=\"3\">Rate this File</font>
<form action=\"<?php echo $PHP_SELF ?>\" method=\"post\">
<select name=\"arating\">
<option value=\"1\">1
<option value=\"2\">2
<option value=\"3\">3
<option value=\"4\">4
<option value=\"5\">5
</select>
<input type=\"submit\" name=\"Submit\" value=\"Submit\" >
</form>
</td></tr>
</table>";
if ( $REQUEST_METHOD == 'POST' )
{
InsertRecord($arating,$file);
}
$file=$obj->filename;
}
now when i do this the page comes up ok, but when i try to submit an entry from the drop down box it gives me a 404 error saying that http://www.ipwnj00.net/<?php%20echo%20/ ... ds.php3%20?> can't be found. i've taken it out of the loop, and it submits it to the database, but then the form obviously isn't included with all the rows that i need. it also can't refresh without resending the information. like i said i'm really really new to php so any help would be appreciated.
post forms in loops
Moderator: General Moderators
<?php echo $PHP_SELF ?> .. you are already in 'PHP mode' when you do this, so you want something like.
Code: Select all
while($obj=mysql_fetch_object($result))
{
?>
<td>
<font color="white" size="3">Rate this File</font>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<select name="arating">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
</select>
<input type="submit" name="Submit" value="Submit" >
</form>
</td></tr>
</table>
<?php
if (isset($_POST['arating']))
{
$file=$obj->filename;
InsertRecord($_POST['arating'],$file);
}
}thanks a lot. i'll try the header() function out and see how it works. alright. last question, i promise =) in the code that markl999 suggested, i'm able to create a drop down box from each query from the database like i needed, but when i submit a rating for a file to the database with the InsertRecord() function, it inserts the rating along with the filename of every other row recieved in the while() loop. so if i have 3 rows queried on the screen with files called blah1.zip, blah2.zip, blah3.zip, and i try to rate blah1.zip, the other blah2.zip and blah3.zip also get that rating. what do i need to do to make each drop down list unique to the row it should be associated with? thanks again for all the help