Jump to content

Form Proccesing.


sepoto
 Share

Recommended Posts

I have a form that contains many checkboxes. The following code runs many times in a while loop.

echo "<input type='checkbox' name='" . $ID . "' value='" . $ID . "' />Delete<br />";

I never know what the value of $ID will be. $ID is the value of the primary key of the record to be deleted. The entire code is below. My problem is how do I process the form once it is submitted?

<?php$radio = $_POST['radio'];mysql_connect('edita','edita','edita');@mysql_select_db('methane') or die( "Unable to select database");$query="SELECT * FROM planning WHERE import_date='" . $radio . "'";$result=mysql_query($query);$num=mysql_numrows($result);?><html><head><title>Division View</title></head><style>	body {		overflow: auto;	}		p {		white-space:nowrap;	}</style><body>	<form action='deleterecords.php' method='post'>		<?php		echo "Displaying ";		echo $num;		echo " records...";		echo "</br></br>";		$X=0;		while ($X < $num) {		$ID=mysql_result($result,$X,"idplanning");		echo "<div style='border: solid 1px black'>";		$app_date=mysql_result($result,$X,"app_date");		echo "<strong>Application Date: </strong>";		echo $app_date; echo "</br>";		$case_number=mysql_result($result,$X,"case_number");		echo "<strong>Case Number: </strong>";		echo $case_number; echo "</br>";		$address=mysql_result($result,$X,"address");		echo "<strong>Address: </strong>";		echo "<a href=\"methanezone.php?ID=";		echo $ID;		echo "\">";		echo $address;		echo "</a><br>";		$cdn=mysql_result($result,$X,"cdn");		echo "<strong>CDN#: </strong>";		echo $cdn; echo "</br>";		$comm_plan_area=mysql_result($result,$X,"comm_plan_area");		echo "<strong>Community Plan Area: </strong>";		echo $comm_plan_area; echo "</br>";		$proj_desc=mysql_result($result,$X,"proj_desc");		echo "<strong>Project Description: </strong>";		echo $proj_desc; echo "</br>";		$request_type=mysql_result($result,$X,"request_type");		echo "<strong>Request Type: </strong>";		echo $request_type; echo "</br>";		$app_contact=mysql_result($result,$X,"app_contact");		echo "<strong>App Contact: </strong>";		echo $app_contact;		echo "<br>";		echo "<input type='checkbox' name='" . $ID . "' value='" . $ID . "' />Delete<br />";		echo "</div></br>";		$X++;		}		?>	<input type="submit" value="Delete" />	</form></body></html>

The following is my old code which only deleted one record at a time. I am trying to modify this code to pick up the value of all the checkboxes from the form above. The number of records is constantly in flux. How can I do this?

<?php$button = $_POST['submit'];echo $button;mysql_connect('edita','edita','edita');@mysql_select_db('methane') or die( "Unable to select database");$query="DELETE FROM `methane`.`planning` WHERE `idplanning`='" . $button . "'";$result=mysql_query($query);?><html><head></head><body><a href="http://www.sepsserver.com/methane">Home</a></body>

THANK YOU!!!!!!

Edited by sepoto
Link to comment
Share on other sites

http://www.html-form-guide.com/php-form/ph...m-checkbox.htmlIn summary, you will want to make the checkboxes part of an array by giving them all the same name in the form and adding [] to the end of the name. Make your form rendering loop give each checkbox a value equal to the id retrieved from the database. Then they will come across to PHP as an array in POST, and the values will be the id's (the value of each checkbox).From there, you would establish a (single) connection to the database, and then use a loop to execute multiple SQL statements to DELETE the records, or whatnot.
Link to comment
Share on other sites

Thank you very very much for your reply... This is what I did to create the program I was after...

echo "<input type='checkbox' name='deleteid[]' value='" . $ID . "' />Delete<br />";

deleterecords.php

<?php$checkboxes = $_POST['deleteid'];mysql_connect('184.106.83.187','sep','oilwell123');@mysql_select_db('methane') or die( "Unable to select database");foreach ($checkboxes as & $value) {$query="DELETE FROM `methane`.`planning` WHERE `idplanning`='" . $value . "'";echo $query . "<br>";$result=mysql_query($query);}?><html><head></head><body><p> Selected records have been deleted...</p><a href="http://www.sepsserver.com/methane">Click to continue...</a></body>

Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...