session not destroyed?????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raj86
Forum Commoner
Posts: 25
Joined: Tue Sep 29, 2009 12:28 am

session not destroyed?????

Post by raj86 »

friends
on a single form i have to submit the posted data into the database......for that i m using validateInput(); function

Code: Select all

function validateInput() 
{
 if($error==0 && trim($_POST['name']) == "")
    {
        return "Please enter student name.";
		$error=1;
    }  
if($error==0 && trim($_POST['id']) == "")
    {
        return "Please enter student ID.";
		$error=1;
    } 
return "validated";
}
once the function return validated my data goes to the table it show the message "Data entered succesfully". when i click OK and refresh the same page , same data will insert again. I have used the session_unset(); but this also not working

Code: Select all

$isError = validateInput();
	if($isError=="validated")
	{
		$query = "INSERT INTO `software` (`SNO`,`NAME`, `ID`, `HOSTEL`, `SOFTWARE`, `URL`, `SIZE`) VALUES ('$sno','$name', '$id', '$hostel', '$software', '$url','$size')";

		$result = mysql_query($query)  or die ("Error in query: $query<br/>");
		if($result)
		{	
			print '<script>alert("Data entered succesfully")</script>';
			$done=true;
			session_unset(); 
			session_destroy();
			$sno++; 
		}      
	}
	else 
	{
		echo "<br><center><font color='red'>$isError</font></center>";
	}
thank you
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: session not destroyed?????

Post by JakeJ »

Try resetting your form after it's submitted. That will clear the data off of the form and should prevent the problem you're talking about. But you're submitting form data which can be done without using sessions so clearing session data isn't really going to help you there.

Alternatively, you could test for whether or not there is a valid session before allowing the database insert. That would solve your problem too.
Post Reply