Page 1 of 1

session not destroyed?????

Posted: Sat Aug 28, 2010 12:41 am
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

Re: session not destroyed?????

Posted: Sun Aug 29, 2010 12:21 am
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.