Solved

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

Posted on 2013-12-09
13
459 Views
Last Modified: 2013-12-10
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
Comment
Question by:selhamawy
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39707790
Have you checked if $_POST["chkDel"] is set?

Try this:

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

HTH,
Dan
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39707827
@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
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39707831
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
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39708267
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39708269
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
 

Author Comment

by:selhamawy
ID: 39708685
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39708734
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
 

Author Comment

by:selhamawy
ID: 39708742
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39708747
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
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39708813
Are my posts invisible again??
0
 

Author Comment

by:selhamawy
ID: 39708984
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
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39709015
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
 

Author Comment

by:selhamawy
ID: 39709396
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now