This topic is locked
[SOLVED]

 DATABASE API and Custom Button

1/12/2020 4:49:16 PM
PHPRunner General questions
H
harveyspecter author

Hello,
I need a button on the Edit Page which redirects you to another tables specific edit page.
So there is only common key is a field called "file_number".
Need to select the same file finding its "ID" by file_number (dosya_no) and redirect me to there.
I tried this:
On Server:



$data2 = $button->getCurrentRecord();

$dosya_no = $data2["dosya_no"];
$rs = DB::Query("select * from dosyalar_all where dosya_no=$dosya_no");

while( $data = $rs->fetchAssoc() )

{

$result["record"] = $data["ID"];

}


Client After:



var $data1 = result.record["ID"];

location.href = 'dosyalar_all_edit.php?editid1='+$data1;


But didnt worked out. It only takes me to list page of redirect page.
Need help thanks alot!

A
acpan 1/12/2020

Maybe you can:
alert('dosyalar_all_edit.php?editid1='+$data1);
and paste it to the browser and see if you can access it.
ACP

A
acpan 1/12/2020

I think there is an error at Client After event:
var $data1 = result.record["ID"];
should be
var data1 = result["record"];
AND
location.href = 'dosyalar_all_edit.php?editid1='+$data1;
Should be:
location.href = 'dosyalar_all_edit.php?editid1='+data1;
Also alert or console.log the values will help you see where the problem is as mentioned in previous post.
ACP

H
harveyspecter author 1/13/2020



I think there is an error at Client After event:
var $data1 = result.record["ID"];
should be
var data1 = result["record"];
AND
location.href = 'dosyalar_all_edit.php?editid1='+$data1;
Should be:
location.href = 'dosyalar_all_edit.php?editid1='+data1;
Also alert or console.log the values will help you see where the problem is as mentioned in previous post.
ACP


Thanks. I tried but didnt worked out. Anything else?
I wrote it to consele an get this error:

VM253:1 Uncaught ReferenceError: data1 is not defined

at <anonymous>:1:50

(anonymous) @ VM253:1
Admin 1/13/2020

You need to proceed step by step. As a very first step you need to make sure your SQL query in Server event is correct and returns results.

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

A
acpan 1/13/2020

data1 is probably empty, may be your SQL returns no result or error.
As said, log ALL your values something like that:
Server:



$data2 = $button->getCurrentRecord();

$dosya_no = $data2["dosya_no"];
// log

$result["log_var"] = "dosya_no=".$dosya_no;
$sql = "select * from dosyalar_all where dosya_no=$dosya_no";
$rs = DB::Query($sql);

$result["log_var"] .= " | SQL=$sql";
while( $data = $rs->fetchAssoc() )

{

$result["record"] = $data["ID"];

}
$result["log_var"] .= " | record_id=".$result["record"] ;


Client After:



var log_var = result["log_var"];

var data1 = result["record"];

var url = 'dosyalar_all_edit.php?editid1='+data1;

log_var = log_var + " | url=" + url;

console.log(log_var);
location.href = url;


ACP

H
harveyspecter author 1/13/2020



You need to proceed step by step. As a very first step you need to make sure your SQL query in Server event is correct and returns results.

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm


THANKS ALOT!
Logging solved my problem. I saw the key columns was wrong.