This topic is locked
[SOLVED]

 Saving Global Variable in SAME TABLE

1/19/2011 4:40:09 AM
PHPRunner General questions
bbarker author

Before I add a new record, I want to include a Global Session Variable (UserID) as part of the record.
Where's the best place to do this? Using the EVENTS example in the manual, I keep getting TWO records saved - one with the Global Variable by itself and then the other record, which contains all of the table data (but NOT the Session variable).

global $conn;

$strSQLInsert = "insert into tblvendors (Editor) values ('".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);


I don't want it to save to a separate record, or different table.
A simple way to show what I want to do is here:

$data["tblvendors_Editor"] = $_SESSION["UserID"];



And then the "tblvendors_Editor" would save along with all of the other fields.
Maybe I shouldn't be using an Event for this?

Sergey Kornilov admin 1/19/2011

That's very simple:

$values["Editor"]=$_SESSION["UserID"];
bbarker author 1/19/2011



That's very simple:

$values["Editor"]=$_SESSION["UserID"];



Thanks $values, not $data. Dang it.
Now, where do I post this? As an Event?

It doesn't work using BEFORE RECORD ADDED. It's looking for a function.

Sergey Kornilov admin 1/19/2011

BeforeRecordAdded is correct event for this.
You need to explain what exactly is happening.

bbarker author 1/19/2011

Thanks for responding.
When I SAVE, it appears to process okay, but the data is still in the fields. No Error message and no Success message.
Normally, after a successful SAVE, the fields are blank - and a green Success message appears at the top.
It saved like this in the event.php file.

// Before record added

function BeforeAdd(&$values,&$message,$inline)

{



// Place event code here.

//Added to capture name of person who added the record

$values["LastEditor"]=$_SESSION["UserID"];

;

} // function BeforeAdd
Sergey Kornilov admin 1/19/2011

I guess you removed "return true;" statement from the end of BeforeAdd event. That's why.

bbarker author 1/19/2011

Sergy,

Thank you. That is exactly what I did... It now works!!
Worked too late last night on this... two simple mistakes. arghhh...

I have a new question, but I'll put it in a new post.

Thanks again.