This topic is locked

Variables not resolving properly

9/22/2006 2:24:30 PM
PHPRunner General questions
G
gawde author

Hello all,
I am trying to pass a value between the Before Edit and After Edit events. I used a technique I found on the forum, but am not getting the expected results. I set the variable as follows:

$_SESSION["Temp_id"] = $values["Temp_id"];
When I echo $_SESSION["Temp_id"] in the After Edit event it displays "Temp_id" (no quotes), not the actual value of Temp_id. I tried placing single and double quotes around $values["Temp_id"], but no help.

This should be simple, so what am I doing wrong? Note: using version 3.0 build 119.

Alexey admin 9/22/2006

Hi,
please ensure that you spell the field name properly. Field names are case sensitive here.

If this doesn't help please show me your BeforeEdit and AfterEdit events code.

G
gawde author 9/22/2006

Hi,

please ensure that you spell the field name properly. Field names are case sensitive here.

If this doesn't help please show me your BeforeEdit and AfterEdit events code.


Hello Alexey,
Spelling seems correct so the BeforeEdit and AfterEdit events follow. I truncated the AfterEdit event since the bottom does not apply. It is not evident from the event code but I assure you the field "Co_ID" exists in the `_Company`table.
Thanks again.
function BeforeEdit(&$values, $where)

{
// Parameters:

// $values - Array object.

// Each field on the Edit form represented as 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited
//** Custom code ****

// put your custom code here

global $conn,$strTableName;
$strSQL = "select `Co_Approved`, 'Co_IDauto' from `_Company` where ".$where;

$rs=db_query($strSQL,$conn);

$data=db_fetch_array($rs);
if (is_null($data["Co_Approved"]))

{

if (!$data["Co_Approved"] == $values["Co_Approved"])

{

$values["Co_ID"]=$data["Co_IDauto"];

//$values["Co_ID"]=$values["Co_IDauto"];

$passvar1 = "PASS";

// $values["Co_Password"]="concat('".$passvar1."',".$data["Co_IDauto"].")";
$random_string = "abcdefghijkmnopqrstuvwxyz123456789";

$my_string = " ";

$length = 7;

while(strlen($my_string) < $length)

{

$myrand=rand(0,strlen($random_string));

$my_string .= $random_string{$myrand};

}

$values["Co_Password"] = "'".trim($my_string)."'";

$values["Co_Invoice"]=$values["Co_Approved"];

$_SESSION["approval"] = "true";

$_SESSION["Co_ID"] = $values["Co_ID"];

//echo " SESSION ID = ".$_SESSION["Co_ID"];

}

}
return true;
// return true if you like to proceed with editing this record

// return false in other case
}
function AfterEdit()

{

//** Custom code ****

// put your custom code here

global $conn, $sendapproval, $sendtowerID;

//echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sendapproval =" .$_SESSION["approval"];

// echo '<script> alert("No record for SESSION = '.$_SESSION["Co_ID"].'");</script>';

//echo '<script> alert("No record for REQUEST = '.$_REQUEST["editid"].'");</script>';
$_SESSION["approval"] = "false";
if ($_SESSION["approval"] == "true")

{
$_SESSION["approval"] = "false";

$strSQL2 = "select `Co_ID`, `Co_Email`, `Co_Name`, `Co_Contact`, `Co_Password` from `_Company` where `Co_IDauto` = ".$_REQUEST["editid"];

$rs2=db_query($strSQL2,$conn);

$data2=db_fetch_array($rs2);

//echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SESSION =" .$_SESSION["Co_ID"];

//echo '<script> alert("No record for SESSION = '.$_SESSION["Co_ID"].'");</script>';

Alexey admin 9/23/2006

Greg,
you confuse apostrophes (') with backquotes (`) in your SQL string.

Replace this line in your code:

$strSQL = "select `Co_Approved`, 'Co_IDauto' from `_Company` where ".$where;

with the following:

$strSQL = "select `Co_Approved`, `Co_IDauto` from `_Company` where ".$where;

G
gawde author 9/23/2006

Greg,

you confuse apostrophes (') with backquotes (`) in your SQL string.

Replace this line in your code:

with the following:


Yup, that will do it every time. Sorry to have wasted your time. I should have found that myself.

Thanks much.