This topic is locked
[SOLVED]

 Update Event not working

5/30/2011 3:25:53 PM
PHPRunner General questions
bbarker author

MasterTable: tblvendors

....Field: Prepaid
Details: tblstalls
I'm trying to update the tblvendors AFTER adding a record to tblstalls.

I think that I've tried ALL of the different events without success.

(and many, many variations of this Update command.

global $conn;

$strSQLUpdate = "UPDATE tblvendors SET Prepaid = ".$_SESSION[`Prepaid`]."

WHERE VendorID = ".$_SESSION["tblvendors_masterkey1"];

db_exec($strSQLUpdate,$conn);


If I remove the Session variables, then the query works.
I just tried the Before SQL query event on the Events tab without success.

J
Jane 6/1/2011

Bill,
$_SESSION['Prepaid'] variable should be defined before. Please make sure you've filled this variable in another event.

bbarker author 6/2/2011



$_SESSION['Prepaid'] variable should be defined before. Please make sure you've filled this variable in another event.


Thanks Jane, but I set it at login, and it shows on the page as part of a variable listing.
My Event is:

// After successful login

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

{
$query = "SELECT Prepaid FROM tbldefaultlookup WHERE DefaultID = 1";

$result = mysql_query($query) or die("Query failed with error: ".mysql_error());

$datatmp=db_fetch_array($result);

$_SESSION["Prepaid"] = $datatmp['Prepaid'];
==================

Any other suggestions?

I'll post to the Demo area as soon as I resolve one other glitch.

bbarker author 6/2/2011

For everyone else - here is the solution that finally worked:
If you want to update a record in the Master table after adding a new record to the Detail table use the following code in the Add page: After record added event of Detail table:

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=58678&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' /> -----------------------------------------

global $conn, $strTableName;

if ($_SESSION[$strTableName."_masterkey1"]){

$strSQLUpdate = "UPDATE MasterTableName SET MasterFieldName = ".$<some value>." WHERE MasterKey = ".$_SESSION[$strTableName."_masterkey1"];

db_exec($strSQLUpdate,$conn);

}

-----------------------------

My configuration was Master=tblvendors and Field=Prepaid, so I modifed it as follows:
global $conn, $strTableName;

if ($_SESSION[$strTableName."_masterkey1"]){

$strSQLUpdate = "UPDATE tblVendors SET Prepaid = ".$_SESSION["Prepaid"]." WHERE VendorID = ".$_SESSION[$strTableName."_masterkey1"];

db_exec($strSQLUpdate,$conn);

}