telsiin Posted June 30, 2008 Share Posted June 30, 2008 Hello everyone Is there such a thing as nested Forms? I have a quick question is it possible to use one form and do a multiple table insert/update combos? I have a form and when a specific condition is met the form is modified and six extra table row/input “radio”/input “text” field are shown in the form. However the original form normally is used to do an insert into a table. With the extra rows I would like to do an update to a different table The reason I don’t just make it a separate page is because I am trying to control when the table can be modified. Link to comment https://forums.phpfreaks.com/topic/112684-1-form-multiple-table-insertupdate-combos/ Share on other sites More sharing options...
.josh Posted June 30, 2008 Share Posted June 30, 2008 instead of name='blah' do name='blah[]' in your form elements, then loop through it like so: foreach ($_POST['blah'] as $blah) { // sanitize // query } Link to comment https://forums.phpfreaks.com/topic/112684-1-form-multiple-table-insertupdate-combos/#findComment-578701 Share on other sites More sharing options...
telsiin Posted July 1, 2008 Author Share Posted July 1, 2008 I not sure I follow you do you suggest I keep one form or make mulitple form on the same page this is what I have now with just one form <form name="Selectclass" method="POST" action="<?php echo $editFormAction; ?>" > <p align="right"> </p> <table width="244" border="0" cellpadding="0" cellspacing="0" class="style1"> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <?php if(($row_Recordset3['charlevel']+1==4)||($row_Recordset3['charlevel']+1==||($row_Recordset3['charlevel']+1==12)||($row_Recordset3['charlevel']+1==16)||($row_Recordset3['charlevel']+1==20)||($row_Recordset3['charlevel']+1==24)||($row_Recordset3['charlevel']+1==28)||($row_Recordset3['charlevel']+1==32)) { print "<tr><td bgcolor='#999999' colspan='2' class='style3'>Raise Ability </td>"; print '<td width="108">'; print '<div align="left">'; print "<tr><td>STR</td><td><input name='score' type='radio' value='str'></td></tr>"; print "<tr><td>DEX</td><td><input name='score' type='radio' value='dex'></td></tr>"; print "<tr><td>CON</td><td><input name='score' type='radio' value='con'></td></tr>"; print "<tr><td>INT</td><td><input name='score' type='radio' value='intell'></td></tr>"; print "<tr><td>WIS</td><td><input name='score' type='radio' value='wis'></td></tr>"; print "<tr><td>CHA</td><td><input name='score' type='radio' value='cha'></td></tr>"; print '</div></td></tr>'; } ?> <tr> <td><input type="submit" name="Submit1" value="Select Class" id="Submit1"></td> <td><input type="submit" name="Submit2" value="Accept Class" id="submit2"></td> </tr> </table> <div align="center"> <input type="hidden" name="MM_insert" value="Selectclass"> </div> </form> The second attempt was to include the second form and inserted in middle of the first form but I don't think it would work ? <form name="Selectclass" method="POST" action="<?php echo $editFormAction; ?>" > <p align="right"> </p> <table width="244" border="0" cellpadding="0" cellspacing="0" class="style1"> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <tr><input name="something.etc" type="text" value="<?php echo $_POST[somethingetc]?>"></tr> <?php if(($row_Recordset3['charlevel']+1==4)||($row_Recordset3['charlevel']+1==||($row_Recordset3['charlevel']+1==12)||($row_Recordset3['charlevel']+1==16)||($row_Recordset3['charlevel']+1==20)||($row_Recordset3['charlevel']+1==24)||($row_Recordset3['charlevel']+1==28)||($row_Recordset3['charlevel']+1==32)) { include_once 'increasestat.php'; //<form method="post" name="increasestats" action="<?php echo $editFormAction;?>"> }?> <tr> <td><input type="submit" name="Submit1" value="Select Class" id="Submit1"></td> <td><input type="submit" name="Submit2" value="Accept Class" id="submit2"></td> </tr> </table> <div align="center"> <input type="hidden" name="MM_insert" value="Selectclass"> </div> This is my insert: if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Selectclass")) { $insertSQL = sprintf("INSERT INTO characterlevels (CharID, charlevel, classlevel, Classid, `Class`, attack_bonus, fortitude, reflex, will, hitpoints, skillpoints,feat) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['CharID'], "int"), GetSQLValueString($_POST['charlevel'], "int"), GetSQLValueString($_POST['classlevel'], "int"), GetSQLValueString($_POST['classid'], "int"), GetSQLValueString($_POST['class'], "text"), GetSQLValueString($_POST['BaseAttackBonus'], "int"), GetSQLValueString($_POST['fortitude'], "int"), GetSQLValueString($_POST['reflex'], "int"), GetSQLValueString($_POST['will'], "int"), GetSQLValueString($_POST['hitpoints'], "int"), GetSQLValueString($_POST['skillpoints'], "int"), GetSQLValueString($_POST['feat'], "int")); This is my update on a different page "increasestat.php": if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "increasestats")) { $updateSQL = sprintf("UPDATE createchr2 SET {$_POST['score']}=%s WHERE CharID=%s", GetSQLValueString($totalscore, "int"), GetSQLValueString($_POST['CharID'], "int")); Link to comment https://forums.phpfreaks.com/topic/112684-1-form-multiple-table-insertupdate-combos/#findComment-578708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.