Jump to content

checkbox on form submits all the results from all the checkboxes, from all the forms on the page


ScrewLooseSalad
Go to solution Solved by ScrewLooseSalad,

Recommended Posts

 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?

Link to comment
Share on other sites

  • Solution

 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 :mellow:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.