Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Notice: Undefined index: chkDel in .....

I get the following error and the record is not deleted

Notice: Undefined index: chkDel in \File_3.php on line 4

I have three files file the description of the purpose of the files as follows:

File_1 -       Search Parameters, Default all records Shown, and
                  Select record(s) to Delete by checkbox
File_2 -       Search Results and
                  Select record(s) to Delete by checkbox
File_3 -      Delete the record(s) in checked and
                  Commit the Transaction

Please can anyone assist here as I cannot seem to locate the problem.

Thank you all in advance

Code:                  
            


<script language="JavaScript"> // included in all three files 
	function onDelete()
	{ 	if(confirm('Do you want to delete these entries?')==true) {
			return true;
		}
		else { 
			return false;
		}
	}
</script>

 

<?PHP	//File_2.php   	

		   	
		ECHO '<form action="File_3.php" method="get">
			<input  style="color: #fff; background-color: #800000; width: 100px; float: left;" 
					type="submit" value="Delete" 
					name="delete" id="frm_delete" />
			</form>	';  // DELETE BUTTON



	
	echo ' <form name="frmMain" action="deleteEntryCommit.php" method="POST" OnSubmit="return onDelete();"> ';

	
	echo "<tbody>";
	echo "<tr>";	
	echo "<table border='0'>";	
	
	//---------------------//
	// Create Table Header //
	//---------------------//
	
	echo "<tr bgcolor='#228B22'>	
			<td class='rowTitleFormat' align='center' > <b> Delete 	</b> </td> 		
			<td class='rowTitleFormat' align='center' > <b> Last Name 	</b> </td> 		
			<td class='rowTitleFormat' align='center' > <b> First Name	</b> </td> 
			<td class='rowTitleFormat' align='center' > <b> Title		</b> </td> 
			<td class='rowTitleFormat' align='center' > <b> E-Mail		</b> </td> 
			<td class='rowTitleFormat' align='center' > <b> Phone		</b> </td>  
			<td class='rowTitleFormat' align='center' > <b> Department	</b> </td> 			
		  </tr> </font>";
		  
		
	echo '<br>';
	
	if($_POST["txtDepartment"] != '.All') {	
			$stid = oci_parse($conn, 	' SELECT  pidm, lname, fname, title, email, phone, ext , dept ' . 
										' FROM view_Name' .
										' WHERE LNAME is not null and' . 
										' LNAME like INITCAP (' . '\'' . $_POST["txtLastName"].'\'' . ')' .
													' and '.			
										' FNAME like INITCAP (' . '\'' . $_POST["txtFirstName"].'\''. ')' .
													' and '.
										' TITLE like ' . '\'' . $_POST["txtTitle"].'\''. 
													' and '.
										' EMAIL like ' . '\'' . $_POST["txtEmail"].'\''. 
													' and '.			
										' PHONE || EXT like ' . '\'' . $_POST["txtPhone"].'\''. ' ' .
													' and '. 
										' DEPT like INITCAP (' . '\'' . $_POST["txtDepartment"].'\''. ')' .
										' order by DEPT, LNAME '	);
	}
	else {	
			$stid = oci_parse($conn, 	' SELECT  pidm, lname, fname, title, email, phone, ext , dept ' . 
										' FROM view_Name' .
										' WHERE LNAME is not null and' . 
										' LNAME like INITCAP (' . '\'' . $_POST["txtLastName"].'\'' . ')' .
													' and '.			
										' FNAME like INITCAP (' . '\'' . $_POST["txtFirstName"].'\''. ')' .
													' and '.
										' TITLE like ' . '\'' . $_POST["txtTitle"].'\''. 
													' and '.
										' EMAIL like ' . '\'' . $_POST["txtEmail"].'\''. 
													' and '.			
										' PHONE || EXT like ' . '\'' . $_POST["txtPhone"].'\''. ' ' .
										' order by DEPT, LNAME '	);
	}
		
	oci_execute($stid); 
	
	echo "<tr bgcolor='#228B22'>";  		

	$counter = 1;
	
	//********************//	
	// Populate Directory //			
	//********************//
	while ($row = oci_fetch_array($stid, OCI_BOTH)) {			
		if(multipleof2($counter)){
			echo "<tr class='rowResultFormat' bgcolor='#FFFACD'> "; } 
		else {
			echo "<tr cclass='rowResultFormat' bgcolor='#c98d11'> "; } 
		echo '<td 	class="rowResultFormat" align="center"> 
					<input type="checkbox" name="chkDel[]" value="' . $row["PIDM"] . '"></td>	';
		echo "<td class='rowResultFormat' >" . ($row['LNAME']) . "</td> " ;			
		echo "<td class='rowResultFormat' >" . ($row['FNAME']) . "</td>";
		echo "<td class='rowResultFormat' >" . ($row['TITLE']) . "</td>" ; 
		echo "<td class='rowResultFormat' >" . ($row['EMAIL']) . "</td>";
		echo "<td class='rowResultFormat' >" . ($row['PHONE']) . ($row['EXT']) . "</td>";
		echo "<td class='rowResultFormat' >" . ($row['DEPT'])  . "</td>";				
		echo "</font> </tr>\n";	
		$counter++;	
	}

echo "</tbody>	";



echo "</table><br>";

?>


<?PHP 	//File_3.php
	for($i=0;$i<count($_POST["chkDel"]);$i++) {
		if($_POST["chkDel"][$i] != "") {
			$objParse = oci_parse($conn, "DELETE FROM table_Name WHERE pidm = '" . $_POST["chkDel"][$i] . "' ");
			$objExecute = oci_execute($objParse, OCI_DEFAULT);
		}
	}
	oci_commit($conn); //*** Commit Transaction ***//
	oci_close($conn);
?>

Open in new window

0
selhamawy
Asked:
selhamawy
  • 4
  • 4
  • 2
  • +2
1 Solution
 
Dan CraciunIT ConsultantCommented:
Have you checked if $_POST["chkDel"] is set?

Try this:

if(isset($_POST["chkDel"])) { your code here }
else echo "Not set"

HTH,
Dan
0
 
RobOwner (Aidellio)Commented:
@Dan is on the money.  The reason you have to check if it is set or not is because the chkDel is an array of checkboxes.  When no checkboxes are selected and you click the delete button, nothing to do with the checkbox is sent to the server.  It's not like it sends that the checkbox is off, the browser just doesn't send anything.
0
 
RobOwner (Aidellio)Commented:
Here is a demo http://phpfiddle.org/api/run/g7f-ds0

first check one or many of the checkboxes and see the result. You'll see the "mycheckbox" variable with the indexes of the ones checked

Then go back and uncheck all and submit.  You won't see the "mycheckbox" variable at all.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Chris StanyonCommented:
As an addition to what Dan says, you don't need to do a for() loop and check against an empty value. An empty check box doesn't get submitted, so if it exists in the array, it was checked. Here's the normal way of doing it:

if (isset($_POST['chkDel'])) {
   foreach ($_POST['chkDel'] as $chk) {
      $objParse = oci_parse($conn, "DELETE FROM table_Name WHERE pidm = '$chk'");
      $objExecute = oci_execute($objParse, OCI_DEFAULT);
   }
}

Open in new window

0
 
Ray PaseurCommented:
Here is an excerpt from file2.php, which appears to be using the GET method to call the action script file3.php.  I believe that you want to call with the POST method for two reasons.  First, your data will be found where you expect it, in $_POST and second, you must never use a GET method if your script can change the data model.  

The reasons for this protocol restriction are fairly complicated but a simple example will help.  Let's say you have a delete script that uses the GET method.  You can start this script from the browser with a URL like delete.php?id=1 and it will delete record #1.  That also means that a malicious or stupid person could create a web page with link after link saying delete.php?id=2, delete.php?id=3, etc.  What do you suppose would happen if someone fed that page to Google and Google followed all the links?

		ECHO '<form action="File_3.php" method="get">
			<input  style="color: #fff; background-color: #800000; width: 100px; float: left;" 
					type="submit" value="Delete" 
					name="delete" id="frm_delete" />
			</form>	';  // DELETE BUTTON

Open in new window

0
 
selhamawyAuthor Commented:
Ray Paseur,

Thanks for the heads up on the security breach.
I changed it to post instead of get and still have errors...

Also:
it is still not calling the onDelete() script before going to File_3
this is used to confirm the delete
also it is still not passing chkDel  from File_2 to File_3.
this seems to have been the problem from the beginning....
0
 
Chris StanyonCommented:
Right - your file2.php has 2 forms - the first one has a DELETE button that will submit an empty form to your file3.php script, and the second form has all the form fields but no submit, so there's no way of submitted the form to your script page (deleteEntryCommit.php)
0
 
selhamawyAuthor Commented:
Dan ,

Thanks for the advise and as suspected it is not being passed to file_3

Tagit,

my problem is that i am checking the box(es) but they are not being passed to file_3.
File_1 works fine i dont know why File_2 is not working.
File_1 also has the ability to delete as well..
0
 
Ray PaseurCommented:
You might want to step back to a simpler example, master that, and build up from there.  Here is how to handle HTML forms in PHP:
http://php.net/manual/en/tutorial.forms.php
0
 
Chris StanyonCommented:
Are my posts invisible again??
0
 
selhamawyAuthor Commented:
Chris,

Sorry I did not see your comment.

I think you may have something.
Please elaborate because I don't follow...

Thanks in advance...

"and May the Odds be Ever in Your Favor" - The Hunger Games
0
 
Chris StanyonCommented:
You have one form that only contains a Submit button:

<form action="File_3.php" method="get">
    <input type="submit" value="Delete" name="delete" id="frm_delete" />
</form>

Open in new window

When the 'Delete' button is clicked that form is sent to File_3.php, but the form doesn't contain any form fields, to there is no data to send.

You then have another form that contains all your tickboxes, and is wired up to your javascript function:

<form name="frmMain" action="deleteEntryCommit.php" method="POST" onSubmit="return onDelete();">
<input type="checkbox" name="chkDel[]" value="$row["PIDM"]">
...

Open in new window

This form has no Submit button, so there is no way of sending the data anywhere. Even if there was a Submit button, you would be sending the form data to a file called deleteEntryCommit.php, which you haven't shown us so we have no idea what that does!

From what I can gather, you want one form that contains all your tickboxes - you set the action of this form to File_3.php and the method to POST, and you include your Delete button inside that form. Hook up your JS if you need to, and then check the results of the tickboxes as per my earlier comments - by using a foreach() loop.
0
 
selhamawyAuthor Commented:
Chris,

WOW that did it.....
I was tearing whats left of my hear out.

Thanks a BILLION...

your reward...

"One Ring to Rule them All..." - The Lord of the Rings,  J.R.R. Tolkien
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now