Page 1 of 1

record re-insertion problem on refreshing

Posted: Sun Nov 16, 2003 11:21 pm
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

Posted: Sun Nov 16, 2003 11:46 pm
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 ?

Refreshing problem

Posted: Mon Nov 17, 2003 12:08 am
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

Posted: Mon Nov 17, 2003 12:35 am
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>

refreshing problem

Posted: Mon Nov 17, 2003 1:32 am
by shan123
thanks paddy,
it worked ...

Shantanu