Pineapple Posted June 13, 2006 Share Posted June 13, 2006 Hey guys, very very very new to PHP and I'm stumped on this problem. I have a while loop that pulls the rows out of a database and outputs each one in a different row of a table. Within each table I also have a form to update the information if desired. However, it seems like the way I'm submitting the form, it's only submitting the first form regardless of which submit I select.My question then is, how do I distinguise one submit button from another? My first thought was to append the iteration number or the id number of the row to the name of the button, but then IF statement doesn't work right.Any help you guys can offer would be really appreciated. Here'es what I've got so far:[code]$result = mysql_query("SELECT * FROM schedule",$db);$count = 0;while($row = mysql_fetch_array($result)){$count++;?> <tr> <td> <div class="name"> <?php echo "$row[name]";?> </div> </td> <td width="10%"> <div class="date"><?php echo "$row[sun_start] - $row[sun_stop]"; if ($submit) { // process form echo "$row[id]"; $sql = "UPDATE schedule SET sun_start = $time WHERE id = $row[id]"; $result = mysql_query($sql); } else{ // display form?> <form method="post" action="<?php echo $PHP_SELF?>"> <input type="text" value="<?php echo "$row[sun_start]";?>"> <select name="time"> <option>12:00</option> <option>12:30</option> <option>01:00</option> </select> <br><br> <input type="submit" value="Submit" name="submit"> </form><?php}?> </div> </td> </tr><?php } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11933-forms-inside-while-loop/ Share on other sites More sharing options...
.josh Posted June 14, 2006 Share Posted June 14, 2006 i can't really follow the logic of your script without knowing what it is you are attempting to do here, but assuming that the logic is working the way you do want it to, what you need to do is in your submit input tags do this:<input type="submit" value="Submit" name="submit[!--coloro:red--][span style=\"color:red\"][!--/coloro--][][!--colorc--][/span][!--/colorc--]">and in your if statement you would do this (assuming that's why you have that $count in there):[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if ($submit[!--coloro:red--][span style=\"color:red\"][!--/coloro--][$count][!--colorc--][/span][!--/colorc--]) { . . .}[/quote]and you are gonna want to put your $count++ at the end of your while loop not at the beginning cuz the $submit array (like all arrays) starts at zero not one. Quote Link to comment https://forums.phpfreaks.com/topic/11933-forms-inside-while-loop/#findComment-45358 Share on other sites More sharing options...
poirot Posted June 14, 2006 Share Posted June 14, 2006 You know, I didn't see the entire code, but since you have different <form>'s, you don't need to discern between them: the broswer *should* send the selected form only. Quote Link to comment https://forums.phpfreaks.com/topic/11933-forms-inside-while-loop/#findComment-45361 Share on other sites More sharing options...
.josh Posted June 14, 2006 Share Posted June 14, 2006 here's the problem i see in this: say he has form Aform Bform Cif you put information into the fields in form A but click on form C's button, what happens? nothing from form A gets submitted, right? so pineapple, you are going to have to throw in an additional if statement to check to see if the fields actually have stuff in it. but I have to ask, why are you doing lots of forms like that? wouldn't it be more efficient just to have 1 form? your if statement does the exact same thing, no matter which form you submit: update the same column in the same row, based on the same variables. btw, i am assuming that at some point in time before all this in your script, you are doing some kind of $submit = $_POST['submit'];$time = $_POST['time']; right? and also you have this input field:<input type="text" value="<?php echo "$row[sun_start]";?>">since you have no name attached to it, and you don't seem to be doing anything with it, i see no reason for you to be doing it this way. It looks to me like you are just labeling your dropdown for the user. Just simply echo the variable. No need to put it in a text field. Quote Link to comment https://forums.phpfreaks.com/topic/11933-forms-inside-while-loop/#findComment-45368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.