This topic is locked

Redirect pages depending if Record Exist

1/31/2012 2:15:42 AM
PHPRunner General questions
S
Sergej author

What i am trying to do - a table where there will be only one row per user...so before adding it will check if whether field username is populated or not

so i would like something like this - if the username field is empty it should open add page if not only edit page to edit already entered data.

before load event on a list page
$strSQLExists = "select * from ProspectiveFirmQuestionnaireGeneral WHERE Username='".$_SESSION["UserID"]."'";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
if($data)
{

header("Location: ProspectiveFirmQuestionnaireGeneral_edit.php");

exit();
}
else
{
header("Location: ProspectiveFirmQuestionnaireGeneral_add.php");

exit();

}

But it doesn't work? Can you help me.

Thnx...

C
cgphp 1/31/2012

Where do you put that code? it doesn't work, doesn't help us. We need more info.

S
Sergej author 1/31/2012



Where do you put that code? it doesn't work, doesn't help us. We need more info.



Since i'm opening the page in question as Add page i placed the event in Add:Page before process

C
cgphp 1/31/2012

If you have put that code in the "Add:Page before process" event of ProspectiveFirmQuestionnaireGeneral add page and $data doesn't exist you are in a infinite loop. You can remove the else branch:

$strSQLExists = "select * from ProspectiveFirmQuestionnaireGeneral WHERE Username='".$_SESSION["UserID"]."'";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
if($data)

{

header("Location: ProspectiveFirmQuestionnaireGeneral_edit.php");

exit();

}