ScrewLooseSalad Posted April 11, 2013 Share Posted April 11, 2013 I have made a page that lists all the products in a MySQL database as a form, so the user can amend details as they view it, this I've done by listing each row in the table as a form, with a selection of buttons on the end; this strategy has worked for me very well for the last few weeks, however I have decided to add check-boxes to the page, and when submitting a form on one of the rows of the table, the form submits all of the check-boxes for some reason; its taken me a day to figure out that this was why I was getting peculiar behaviour from the php code that deals with the results of the form on the next page. The checkboxes are pre-checked with the information from the database, the idea was to have the details in the 'group' column change when the selection of check-boxes were changed, however, although the database is read correctly, and the checking on check-boxes works, when the form is submitted the form submits all of the selections on the entire page across all of the forms. The code for the form is as follows: echo "<form action='action.php?part=$group' method='post'>"; echo "<table>"; echo "<tr align=center><td>Part No</td><td>Description</td><td>Stock</td><td>Notes</td> <td align='center' title='ProductLine1'>L</td> <td align='center' title='ProductLine2'>R</td> <td align='center' title='ProductLine3'>S</td> <td align='center' title='ProductLine4'>V</td> <td align='center' title='ProductLine5'>Z</td> <td align='center' title='ProductLine6'>U</td> <td align='center' title='ProductLine7arts'>P</td> <td align='center' title='ProductLine8'>X</td> </tr>"; while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; //MAIN FORM echo "<td><input type='text' name='company_PartNo' maxlength='10' value='$row[company_PartNo]' size='3' readonly /></td>"; echo "<td><input type='text' name='Part_Name' maxlength='65' value='$row[Part_Name]' size='30' readonly /></td>"; echo "<td><input type='text' name='Stock' maxlength='10' value='$row[Stock]' size='3' /></td>"; echo "<td><input type='text' name='Notes' maxlength='65' value='$row[Notes]' size='30' /></td>"; //SYSTEM echo "<td><input type='checkbox' name='system[]' title='ProductLine1' value='PL1' "; if (strpos($row['group'],'Prod1') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine2' value='PL2' "; if (strpos($row['group'],'Prod2') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine3' value='PL3' "; if (strpos($row['group'],'Prod3') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine4' value='PL4' "; if (strpos($row['group'],'Prod4') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine5' value='PL5' "; if (strpos($row['group'],'Prod5') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine6' value='PL6' "; if (strpos($row['group'],'Prod6') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine7' value='PL7' "; if (strpos($row['group'],'Prod7') !== false) { echo "checked></td>";} else { echo "></td>";} echo "<td><input type='checkbox' name='system[]' title='ProductLine8' value='PL8' "; if (strpos($row['group'],'Prod8') !== false) { echo "checked></td>";} else { echo "></td>";} //BUTTONS echo "<td><input type='submit' name='store' value='Store'/> <input type='submit' name='delete' value='Delete'/> <input type='submit' name='edit' value='Edit'/> <input type='submit' name='move' value='Move'/></td>"; //HIDDEN DETAILS /* echo " <div style='height:0px;width:0px;'> <input type='text' name='PartID' maxlength='65' style='visibility:hidden;' value='$row[PartID]' size='1'/> </div>"; */ echo "</tr>"; } echo "</table>"; echo "</form>"; Can someone help me bring order to this chaos? Quote Link to comment Share on other sites More sharing options...
Solution ScrewLooseSalad Posted April 11, 2013 Author Solution Share Posted April 11, 2013 I have made a page that lists all the products in a MySQL database as a form, so the user can amend details as they view it, this I've done by listing each row in the table as a form, with a selection of buttons on the end; this strategy has worked for me very well for the last few weeks, however I have decided to add check-boxes to the page, and when submitting a form on one of the rows of the table, the form submits all of the check-boxes for some reason; its taken me a day to figure out that this was why I was getting peculiar behaviour from the php code that deals with the results of the form on the next page. The checkboxes are pre-checked with the information from the database, the idea was to have the details in the 'group' column change when the selection of check-boxes were changed, however, although the database is read correctly, and the checking on check-boxes works, when the form is submitted the form submits all of the selections on the entire page across all of the forms. Can someone help me bring order to this chaos? I figured it out, man I feel like a muppet Quote Link to comment 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.