Djunity Posted February 18, 2010 Share Posted February 18, 2010 Hi all, Im having trouble to get the beneath script to work the thing i can't seem to get workin is the following. The page requests the data from a mysql table using mysql array so there are mutliple row's every row has 3 data colloms 1 id (auto increment) 2 Module name 3 status. after every row the is a submit button so you can submit data from that row (basilcy a on and off button) when i have more than 1 row it doesnt work. With 1 row it works but have to press the submitt buton twice. Any help will be appreciated Regards Djunity <div class="content"> <br /> <a href="?page=view">Module overzicht</a> <br /> <br / > <p><a href="?page=add" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Module toevoegen </a></p> <table id="myTable" class="tablesorter" style="width: 100%;" border="0" cellpadding="0" cellspacing="1" > <thead> <tr> <td height="25px" width="120"><b> Module naam:</b></td> <td height="25px" width="60"><b> Status:</b></td> <td height="25px"width="70"><b> Actie:</b></td> </tr> </thead> <? // get results from database $result = mysql_query("SELECT * FROM Wefact_Modules ORDER BY id") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $form = $row['module']; $id = $row['id']; ?> <tbody> <form method="post" name="form" action="?page=view"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <input type="hidden" name="action2" value="action"> <tr class="hover"> <td height="35px"><? echo $row['module']; ?></td> <td height="35px"><? if ($row['status'] == 1) { echo "<font color='#00FF00'>Online</font>"; }else if ($row['status'] == 0){ echo "<font color='#FF0000'>Offline</font>"; } ?></td> <td height="35px"> <? if ($row['status'] == 1) { ?> <input type="hidden" name="status" value="0" /><a href="javascript: document.form.submit();" class="button"><span class="ui-icon ui-icon-minusthick"> </span>Offline</a> <? }else if ($row['status'] == 0){ ?> <input type="hidden" name="status" value="1" /><a href="javascript: document.form.submit();" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Online</a> <? } ?> </td> </form> </tbody> <? } ?> <? $status = $_POST['status']; if($_REQUEST['action2'] == 'action') { $sql = "UPDATE Wefact_Modules SET status='$status' WHERE id='$id'"; $result = mysql_query($sql); } ?> </table> <br> </td> </tr> </table> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192501-multiple-submit-forms-inside-a-mysql-array-page/ Share on other sites More sharing options...
jl5501 Posted February 18, 2010 Share Posted February 18, 2010 The most obvious problem is the fact that you are not explicitly setting the value of $id that you are using in your update query you need a $id = $_POST['id']; under where you set status Link to comment https://forums.phpfreaks.com/topic/192501-multiple-submit-forms-inside-a-mysql-array-page/#findComment-1014289 Share on other sites More sharing options...
Djunity Posted February 18, 2010 Author Share Posted February 18, 2010 The most obvious problem is the fact that you are not explicitly setting the value of $id that you are using in your update query you need a $id = $_POST['id']; under where you set status That doesn't fix neither the dubble click problem nor does it solve the problem that when i have multipe row's that the submit function doesn't work Link to comment https://forums.phpfreaks.com/topic/192501-multiple-submit-forms-inside-a-mysql-array-page/#findComment-1014358 Share on other sites More sharing options...
Djunity Posted February 18, 2010 Author Share Posted February 18, 2010 Hmmm Allterd the code a bit more it will submit from multiple row's now but still need to dubble click the submit button any idea <div class="content"> <br /> <a href="?page=view">Module overzicht</a> <br /> <br / > <p><a href="?page=add" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Module toevoegen </a></p> <table id="myTable" class="tablesorter" style="width: 100%;" border="0" cellpadding="0" cellspacing="1" > <thead> <tr> <td height="25px" width="120"><b> Module naam:</b></td> <td height="25px" width="60"><b> Status:</b></td> <td height="25px"width="70"><b> Actie:</b></td> </tr> </thead> <? // get results from database $result = mysql_query("SELECT * FROM Wefact_Modules ORDER BY id") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $form = $row['module']; $id = $row['id']; ?> <tbody> <form method="post" name="form<? echo $id; ?>" action="?page=view"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <input type="hidden" name="action2" value="action"> <tr class="hover"> <td height="35px"><? echo $row['module']; ?></td> <td height="35px"><? if ($row['status'] == 1) { echo "<font color='#00FF00'>Online</font>"; }else if ($row['status'] == 0){ echo "<font color='#FF0000'>Offline</font>"; } ?></td> <td height="35px"> <? if ($row['status'] == 1) { ?> <input type="hidden" name="status" value="0" /><a href="javascript: document.form<? echo $id; ?>.submit();" class="button"><span class="ui-icon ui-icon-minusthick"> </span>Offline</a> <? }else if ($row['status'] == 0){ ?> <input type="hidden" name="status" value="1" /><a href="javascript: document.form<? echo $id; ?>.submit();" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Online</a> <? } ?> </td> </form> </tbody> <? $status = $_POST['status']; $id = $_POST['id']; if($_REQUEST['action2'] == 'action') { $update = "UPDATE Wefact_Modules SET status='$status' WHERE id='$id'"; $result2 = mysql_query($update); } } ?> </table> <br> </td> </tr> </table> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192501-multiple-submit-forms-inside-a-mysql-array-page/#findComment-1014359 Share on other sites More sharing options...
Djunity Posted February 18, 2010 Author Share Posted February 18, 2010 Well figured it out after all a friend pointed me in the right direction here is the code that works, the sql update query was after the submit so the page refreshed and loaded the old data from the table en then it updated so after the second submit you see the change. <div class="content"> <br /> <a href="?page=view">Module overzicht</a> <br /> <br / > <p><a href="?page=add" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Module toevoegen </a></p> <table id="myTable" class="tablesorter" style="width: 100%;" border="0" cellpadding="0" cellspacing="1"> <thead> <tr> <td height="25px" width="120"><b> Module naam:</b></td> <td height="25px" width="60"><b> Status:</b></td> <td height="25px"width="70"><b> Actie:</b></td> </tr> </thead> <? $status = $_POST['status']; $id = $_POST['id']; if($_REQUEST['action2'] == 'action') { $update = "UPDATE Wefact_Modules SET status='$status' WHERE id='$id'"; $result2 = mysql_query($update); // var_dump($result2); } // get results from database $result = mysql_query("SELECT * FROM Wefact_Modules ORDER BY id") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $form = $row['module']; $id = $row['id']; ?> <tbody> <form method="post" name="form<? echo $id; ?>" action="?page=view"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <input type="hidden" name="action2" value="action"> <tr class="hover"> <td height="35px"><? echo $row['module']; ?></td> <td height="35px"> <? if ($row['status'] == 1) { echo "<font color='#00FF00'>Online</font>"; }else if ($row['status'] == 0) { echo "<font color='#FF0000'>Offline</font>"; } ?> </td> <td height="35px"> <? if ($row['status'] == 1) { ?> <input type="hidden" name="status" value="0" /><a href="javascript: document.form<? echo $id; ?>.submit();" class="button"><span class="ui-icon ui-icon-minusthick"> </span>Offline</a> <? }else if ($row['status'] == 0) { ?> <input type="hidden" name="status" value="1" /><a href="javascript: document.form<? echo $id; ?>.submit();" class="button"><span class="ui-icon ui-icon-plusthick"> </span>Online</a> <? } ?> </td> </tr> </form> </tbody> <? } ?> </table> <br> </div> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192501-multiple-submit-forms-inside-a-mysql-array-page/#findComment-1014494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.