This topic is locked
[SOLVED]

  functions phprunner

4/21/2010 7:09:10 PM
PHPRunner General questions
T
tin author

Hello all, I'm new to the forum.
I am having trouble implementing a function.
I need to call the function on the "add page".
I cannot figure out where to put the code.

If I manually edit the "credits_add.php" page, and code the function in the page, of course PHPrunner deletes my code when it "builds".
How can I place the function within PHPrunner without having to edit the page manually via an outside editor like dreamweaver ?
My function is this:
function usertrack_num($ucid) {

$num_query = ("select count(*) as CTNumber from credits where UserID = '$ucid'");

$num_result = mysql_query($num_query) or die(mysql_error());

$user_rows = mysql_fetch_array($num_result);

return $user_rows['CTNumber'];
$linenum = usertrack_num($_SESSION['OwnerID']) + 1;

}
Thanks in advance for any insight.
Tin.

Sergey Kornilov admin 4/21/2010

To add your PHP code we recommended to use 'After table initialized' or 'After application initialized' event.

include("customfile.php");


customfile.php needs to reside in the same directory where the rest of files are.
More info:

http://xlinesoft.com/phprunner/docs/how_to_add_external_files.htm

T
tin author 4/22/2010

Thank you for your response.

I will try that and get back.
Thanks again.
quote name='admin' date='21 April 2010 - 07:50 PM' timestamp='1271904604' post='49296']

To add your PHP code we recommended to use 'After table initialized' or 'After application initialized' event.

include("customfile.php");


customfile.php needs to reside in the same directory where the rest of files are.
More info:

http://xlinesoft.com/phprunner/docs/how_to_add_external_files.htm

[/quote]

T
tin author 4/23/2010



To add your PHP code we recommended to use 'After table initialized' or 'After application initialized' event.

include("customfile.php");


customfile.php needs to reside in the same directory where the rest of files are.
More info:

http://xlinesoft.com/phprunner/docs/how_to_add_external_files.htm


I now have problems calling the function.

For testing/learning purposes I have made a simple function. Saved it in custom_functions in the root directory with all the other files.

function is this:
function test_function($cheese){

$cheese = 4;

return $cheese;

}
in the "events" / "add page before display" I placed my include: include("custom_functions.php"); (did an echo hello world as a test and is reading the custom_functions page, so that works)
visual editor/edit as/read only....place now() as a function my page works fine, call MY function test_function($cheese) and it does not work.
HELP PLEASE, I've spent hours reading and testing, looking at my "output" code with dreamweaver, UG.
Thanks

Tin

G
gawde 4/23/2010



I now have problems calling the function.

For testing/learning purposes I have made a simple function. Saved it in custom_functions in the root directory with all the other files.

function is this:
function test_function($cheese){

$cheese = 4;

return $cheese;

}
in the "events" / "add page before display" I placed my include: include("custom_functions.php"); (did an echo hello world as a test and is reading the custom_functions page, so that works)
visual editor/edit as/read only....place now() as a function my page works fine, call MY function test_function($cheese) and it does not work.
HELP PLEASE, I've spent hours reading and testing, looking at my "output" code with dreamweaver, UG.
Thanks

Tin



Hello Tin,
I noticed you said "in the "events" / "add page before display" I placed my include: include("custom_functions.php");" I believe the include should be placed in the 'After application initialized' event (as Admin suggested). Then, place your call in the "add page before display" event. If I read you correctly, that should help.

Greg

T
tin author 4/25/2010



Hello Tin,
I noticed you said "in the "events" / "add page before display" I placed my include: include("custom_functions.php");" I believe the include should be placed in the 'After application initialized' event (as Admin suggested). Then, place your call in the "add page before display" event. If I read you correctly, that should help.

Greg


Thanks Greg,
I did initially have my inlude in the "add page: before process" with no results.

So what I have done is basically skipped "calling" the function from another page, and placed the function in " table events/add page/before record added."

This has some results.
I have tested my code and is fully functional in a page created outside of PHPRunner.
What I am now trying to do with this function is:

on the "add page" where a user is able to "input" for 3 fields of the table, I have a fourth field that I would like to be "dictated" to the user and saved with the other 3 fields.

for example:
first name: (text box)

last name: (text box)

phone number: (text box)

ID# : this will be automatically assigned and written as part of the entire record. (it will be "saved" records by this user +1 )
here's my code to do this:
function usertrack_num($ueid) {

$num_query = ("select count(*) as CTNumber from expenses where UserID = '$ueid'");

$num_result = mysql_query($num_query) or die(mysql_error());

$user_rows = mysql_fetch_array($num_result);

return $user_rows['CTNumber'];

}

$linenum = usertrack_num($_SESSION['OwnerID']) + 1;
I now need to assign $linenum to the PHPRunner variable that would hold this info if it were a normal user typed input field.
first name: (text box)

last name: (text box)

phone number: (text box)

ID# : using php code "add page/before record added" I tried $value = $linenum; with no results
I get an error :

<<< Record was NOT added >>>
Column 'user_c_trak_num' (this is the name of the field in the table) cannot be null.
If it is "null" obviously I am doing something wrong in passing my variable.
any insight??
thank you.

tin

G
gawde 4/26/2010



Thanks Greg,
I did initially have my inlude in the "add page: before process" with no results.

So what I have done is basically skipped "calling" the function from another page, and placed the function in " table events/add page/before record added."

This has some results.
I have tested my code and is fully functional in a page created outside of PHPRunner.
What I am now trying to do with this function is:

on the "add page" where a user is able to "input" for 3 fields of the table, I have a fourth field that I would like to be "dictated" to the user and saved with the other 3 fields.

for example:
first name: (text box)

last name: (text box)

phone number: (text box)

ID# : this will be automatically assigned and written as part of the entire record. (it will be "saved" records by this user +1 )
here's my code to do this:
function usertrack_num($ueid) {

$num_query = ("select count(*) as CTNumber from expenses where UserID = '$ueid'");

$num_result = mysql_query($num_query) or die(mysql_error());

$user_rows = mysql_fetch_array($num_result);

return $user_rows['CTNumber'];

}

$linenum = usertrack_num($_SESSION['OwnerID']) + 1;
I now need to assign $linenum to the PHPRunner variable that would hold this info if it were a normal user typed input field.
first name: (text box)

last name: (text box)

phone number: (text box)

ID# : using php code "add page/before record added" I tried $value = $linenum; with no results
I get an error :

<<< Record was NOT added >>>
Column 'user_c_trak_num' (this is the name of the field in the table) cannot be null.
If it is "null" obviously I am doing something wrong in passing my variable.
any insight??
thank you.

tin



Hello Tin,
I think you have a simple syntax problem. Try changing "$value = $linenum" to this:
$values["user_c_trak_num"] = $linenum;
Greg

T
tin author 4/26/2010



Hello Tin,
I think you have a simple syntax problem. Try changing "$value = $linenum" to this:
$values["user_c_trak_num"] = $linenum;
Greg


THANK YOU so much Greg, and Admin for helping me get through this problem.

It works!!!!
I have spent many hours trying to do this myself, thank you again for your help and direction.
sincerely,

Tin