This topic is locked
[SOLVED]

 Check for existing records and avoiding duplicate entry

4/13/2007 10:17:14 PM
PHPRunner General questions
Z
zebex author

Screenshot:
https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=5005&image=1&table=forumtopics
Hi there,
Im totally lost. See screenshot above, that is my add entry class schedule page.

I want to prevent user from inputting duplicate entries on this page. So, if the user

enter's a duplicate entry, a message would appear. Fields "Time", "Days", "Subject",

"Room" are the fields that phprunner should be checking for duplicate entries.
Here's the code for "After record added" event:
function AfterAdd()

{

//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from AnyTable where AnyColumn='AnyValue'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

else

{

// if dont exist do something else

}
}

Sergey Kornilov admin 4/13/2007

AfterAdd event happens after record was added already.
Use BeforeAdd event for this purpose. In this event you can use $values["FieldName"] to access field value and build correct SQL query.

Z
zebex author 4/14/2007

AfterAdd event happens after record was added already.

Use BeforeAdd event for this purpose. In this event you can use $values["FieldName"] to access field value and build correct SQL query.


Im just starting with sql and php. Im totally lost. I would appreciate if you guide and put me on the right track.

Z
zebex author 4/14/2007



Im just starting with sql and php. Im totally lost. I would appreciate if you guide and put me on the right track.


Finally, figured it out...All working now.
One more thing, supposing I want to display a message " Duplicate Entries, Try Again" for every duplicate entries entered and I want the user to redirect back to classprog_add.php page. I have tried it using the "display a message" and "redirect to another

page" actions but it gives me an error.

Z
zebex author 4/14/2007



Im just starting with sql and php. Im totally lost. I would appreciate if you guide and put me on the right track.


Finally, figured it out...All working now.
One more thing, supposing I want to display a message " Duplicate Entries, Try Again" for every duplicate entries entered and I want the user to redirect back to classprog_add.php page. I have tried it using the "display a message" and "redirect to another

page" actions but it gives me an error.