This topic is locked

directly accessing a record for editing

3/25/2008 1:44:57 PM
PHPRunner General questions
P
paul paulousek author

I'm still trying to achieve the following:

After successful login the editing-view is opened with the respective user's personal record, i.e. without entering the list-view first.

In case that there is no personal record yet, it should be created automatically.
So I tried the following event-code:

(UID and Uid respectively define the ownership of the record, Email is used as the username)
[codebox]// After successful login

function AfterSuccessfulLogin($username, $password,&$data)

{

global $conn;

$strSQLExists = "select from _bewerbung where UID='". $data['Uid']."'";

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

$data=db_fetch_array($rsExists);

if($data)

{

header("Location:_bewerbung_edit.php");

}

else

{

$strSQLInsert = "insert into _bewerbung (UID, Email) values (" . $data['Uid']."," .$username. ")";

db_exec($strSQLInsert,$conn);

$strSQLExists = "select
from _bewerbung where UID='". $data['Uid']."'";

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

$data=db_fetch_array($rsExists);
header("Location:_bewerbung_edit.php");

}
} // function AfterSuccessfulLogin

[/codebox]

This code opens the edit-page, but without loading the record, but with an empty form to create a new one.

I also tried to append a "?editid1=$data[Pkey]" (PKey ist the primary key which is used to reference the records from the *list.php page) argument to "_bewerbung_edit.php", but to no avail.
So how do I get the selected record loaded to the edit-form?

I was arguing that $data = db_fetch_array() would load all the db-fields to the respective form-fields, but, obviously, this isn't the case...

?
tia, paul

Sergey Kornilov admin 3/25/2008

Try the following:

// After successful login

function AfterSuccessfulLogin($username, $password,&$data)

{

global $conn;

$strSQLExists = "select * from _bewerbung where UID='". $data['Uid']."'";

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

$data2=db_fetch_array($rsExists);

if($data2)

{

header("Location:_bewerbung_edit.php?editid1=" . $data2["Pkey"]);

}

else

{

$strSQLInsert = "insert into _bewerbung (UID, Email) values (" . $data['Uid']."," .$username. ")";

db_exec($strSQLInsert,$conn);

$strSQLExists = "select * from _bewerbung where UID='". $data['Uid']."'";

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

$data2=db_fetch_array($rsExists);
header("Location:_bewerbung_edit.php?editid1=" . $data2["Pkey"]);

}
} // function AfterSuccessfulLogin
P
paul paulousek author 3/26/2008

Thanks!
With some tweaking of the quotes - here is what currently and actually works:

[codebox]global $conn;

$strSQLExists = "select from _bewerbung where UID=". $data['Uid'];

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

$data2=db_fetch_array($rsExists);

if($data2)

{

header("Location:_bewerbung_edit.php?editid1=" . $data2['Pkey']);

exit();

}

else

{

$strSQLInsert = "insert into _bewerbung (UID) values (" .$data['Uid'].")";

db_exec($strSQLInsert,$conn);

$strSQLExists = "select
from _bewerbung where UID=". $data['Uid'];

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

$data2=db_fetch_array($rsExists);

header("Location:_bewerbung_edit.php?editid1=" . $data2['Pkey']);

exit();

}

[/codebox]
Thank you Sergey, xline-support is fab!!

Response was quick, "demo-account" (I would name it "support-account") works smoothly and swiftly. And I've learned something...