0

Don't know why my coding appear this error:
"Notice : Undefined index: PK in c:\easyphp1-8\www\associationdeleteprocess.php on line 24"
But I still can delete my database. Who can help me to solve this problem?

This is my "AssociationDeleteProcess.php" coding:

<html>
<head>
<title>Index</title>
</head>

<body background="E-Filing%20Management%20System%20Picture/Snow.gif">

<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>

<form method="post" action="AssociationDeleteProcess.php">

<?php
	$connection = mysql_connect("localhost", "root", "")   
		or die("<font color='#FFFFFF'>Could not connect to MySQL </font>" .mysql_error());

	$selection = mysql_select_db("efiling")   
		or die("<font color='#FFFFFF'>Unable to select database.</font>" .mysql_error());
		
	$submit = $_POST["submit"];
	$PK = $_POST["PK"];
	
	if($submit=="Search")
	{
    		if(isset($_POST["PK"]))
    		{ 
    			$PK = $_POST["PK"];
	  		$sql = "SELECT * from association where PriKey ='$PK'";
	   		$result = mysql_query($sql) 
	  			or die("<font color='#FFFFFF'>SQL select statement failed</font>");
	  
	  		if($row=mysql_fetch_array($result))
       	    		{  
            			echo "<p align='center'><font size='5' face='Arial Rounded MT Bold'><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  : &nbsp;&nbsp;$row[ID] </font></font></p>";
       	        		echo "<p align='center'><font size='5' face='Arial Rounded MT Bold'><font color='#FFFFFF'>Association Name &nbsp;&nbsp; : &nbsp;&nbsp;$row[AssociationName]</font></font></p><br>";
       	        		echo "<input type='hidden' name='PK' value='$row[PriKey]'>";
                		echo "<p align='center'><input type ='submit' name='submit' value='Delete'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
                		echo "<input type ='submit' name='submit' value='Back'></p>";	
            		}
            
	 		else 
	 		{ 
	 			echo "<font size='5' face='Arial Rounded MT Bold'><font color='#FFFFFF'><p align='center'>No record found</p></font></font><br><br>"; 
	 			echo "<p align='center'><input type ='submit' name='submit' value='Back'></p>";	
	 		}
     		}  
	}
	
	if($submit=="Delete")
	{	
		$PK = $_POST["PK"];
    		$sql= "DELETE FROM association WHERE PriKey = '$PK'";
    		$result = mysql_query($sql);
    		echo "<hr><h2><font color='#FFFFFF'><p align='center'>Record Deleted</p></hr></h2><br>";
    		echo "<p align='center'><input type ='submit' name='submit' value='Back'></p>";
 	}   
	
	if($submit=="Back")
	{	
		print "<script language ='javascript'>window.location.href='Association.php'</script>";
 	}
?>


<p align="center"></p>
<p align="center"></p>
<p align="center"></p>
<p align="center"></p>
<p align="center"></p>

</body>
</html>

This is the previous page "AssociationDelete.php" coding:

<html>
<head>
<title>Index</title>
</head>

<body background="E-Filing%20Management%20System%20Picture/Snow.gif">
<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<form method="POST" action="AssociationDeleteProcess.php"> 



<p align="center"><font size='3' face='Arial Rounded MT Bold'><font color='#FFFFFF'>Enter Primary Key to Delete :&nbsp;&nbsp;<input type="text" name="PK" size="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="submit" value="Search" > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Back" > </font></font></p>



</form> 
<p align="center"></p>
<p align="center"></p>
<p align="center"></p>
<p align="center"></p>
<p align="center"></p>

</body>
</html>
4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by kira4
0
$submit = $_POST["submit"];
	$PK = $_POST["PK"];

If $_POST does not exist, you'll get an error. You've correctly used 'isset' elsewhere in your code, but not the first instance.

0

one more thing, apart from above -
$PK = $_POST["PK"];
you doing this thing twice which is not needed actually, just delete the line24 and it should work.

0

You may want to note that for assigning a possibly undefined variable or array index/key the following is the correct method.

$PK = (isset($_POST['PK']))?$_POST['PK']:'';

The above is what line 24 should be.

0

yes, that's always better, but here its not the case.
The guy is doing assigning that variable inside the if(isset($_POST["PK"]))
so actually no need to do isset() again when assigning the value to some other variable, it will be always set inside this loop.
From his code Lines28 -30 here -

if(isset($_POST["PK"]))
    		{ 
    			$PK = $_POST["PK"];
0

yes, that's always better, but here its not the case.
The guy is doing assigning that variable inside the if(isset($_POST["PK"]))
so actually no need to do isset() again when assigning the value to some other variable, it will be always set inside this loop.
From his code Lines28 -30 here -

if(isset($_POST["PK"]))
    		{ 
    			$PK = $_POST["PK"];

Thanks...
I just notice that. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.