This topic is locked
[SOLVED]

 insert default value error

9/27/2010 12:12:49 PM
PHPRunner General questions
T
tedwilder author

hello I want to insert as default a value that is calculated from a field.

so in BEFORE add page I have this :
$sql="select max(substr(numdevis,9)) as mx from devis where substr(numdevis,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="DE";

$str2=date("Ym");

$str3=($data["mx"]+1);

$values["numdevis"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);
because I want the number of th record to be $values["numdevis"]

But when I put in the editor default value for the field numdevis : $values["numdevis"] I get a php error : undefined variable value.

It seems it doesnt have access to db array..

I want when the user open the "add page " the numdevis field filled with the number I get from the little code above.

thank you.

Sergey Kornilov admin 9/27/2010

Move this code to Add page BeforeProcess event and save result in session variable:

$sql="select max(substr(numdevis,9)) as mx from devis where substr(numdevis,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="DE";

$str2=date("Ym");

$str3=($data["mx"]+1);

$_SESSION["numdevis"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);



Then use $_SESSION["numdevis"] as a default value.

T
tedwilder author 9/27/2010



Move this code to Add page BeforeProcess event and save result in session variable:

$sql="select max(substr(numdevis,9)) as mx from devis where substr(numdevis,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="DE";

$str2=date("Ym");

$str3=($data["mx"]+1);

$_SESSION["numdevis"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);



Then use $_SESSION["numdevis"] as a default value.


thanks a lot <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=52975&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />