record re-insertion problem on refreshing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
shan123
Forum Newbie
Posts: 9
Joined: Tue Oct 21, 2003 11:04 pm

record re-insertion problem on refreshing

Post by shan123 »

Hello all,

I'm having a screen on which a list of records is displayed. The screen also has the facility to add a new record.
When I add a new record, it gets added successfully and gets displayed in the list on the same screen. If I press refresh button, then the same record as the previously inserted with different primary key gets added and displayed on the screen.
Anyone who can help me preventing this happen?

Thanks in advance...

Shantanu
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

well, on your page load, are you calling a php file to perform a table update? if so, it could have retained the values and reposted it .

have any code we could peek at ?
shan123
Forum Newbie
Posts: 9
Joined: Tue Oct 21, 2003 11:04 pm

Refreshing problem

Post by shan123 »

Hii ,
Thx. for the reply
foll. is the code snippet we are using for inserting record in DB.

if($_POST['ac'] == "save")
{
if(validateInputs())
{

$objAssignment = new assignment;

$objAssignment->classId = $_POST['classid'];
$objAssignment->type = AddQ($_POST['cmbType']);
$objAssignment->description = AddQ($_POST['txtDescription']);
$objAssignment->note = AddQ($_POST['txtNote']);
$objAssignment->updatedBy = $g_user_Id;
$objAssignment->updatedOn = "now()";

if(!$objAssignment->addAssignmentDetails())
{

}

$query = "SELECT max(ASSIGNMENTID) FROM CLASSASSIGNMENTS ";
//execute the sql for fetching the class info
$sqlConn->executeQuery($query);

$arr=$sqlConn->fetchIndex();

$assignmentId = $arr[0];

$arrInsertionDocs = $_POST["arrAddedDocs"];
$arrDeletedDocs = $_POST['arrAddedDocsDeleted'];

//insert the records in assignment documents
for($cnt=0;$cnt<count($arrInsertionDocs);$cnt++)
{
if($arrDeletedDocs[$cnt] != 'D')
{
$objAssignment->assignmentId = $assignmentId;
$objAssignment->documentId = $arrInsertionDocs[$cnt];

if(!$objAssignment->addDocumentDetails())
{
$query = "DELETE FROM CLASSASSIGNMENTS WHERE ASSIGNMENTID =". $assignmentId;;

//delete the assignment if error in inserting the documents
$sqlConn->executeQuery($sqlAssignment);
}
}
}

}

On the page load, we aren't giving call to any php for updating table or so.
I think this is happening because the value of posted variables is getting retained.

Looking forward for your help.

Thanks and regards,

Shantanu
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

I have not tested this but it should work as long as you don't output to the screen as header won't work.

Code: Select all

<?php
	$submit = (isset($_POST['submit'])?$_POST['submit']:"");
	if($submit=="Press Here")
	{
		//Do your insert stuff here.
		header("Location: temp.php");
	}
?>
<html>
<head>
</head>
<body>
<form action="temp.php" method="post">
<input type="submit" name="submit" value="Press Here">
</form>
</body>
</html>
shan123
Forum Newbie
Posts: 9
Joined: Tue Oct 21, 2003 11:04 pm

refreshing problem

Post by shan123 »

thanks paddy,
it worked ...

Shantanu
Post Reply