This topic is locked
[SOLVED]

Access records via a secondary field

8/24/2021 9:50:52 PM
PHPRunner General questions
S
SteveDickson author

Hi,

Firstly, I am running PHPRunner 10.5 (Build 372561 x64)

I have a project where we sell raffle tickets online and wish to make this available to other organisations. They need to display a URL linking to "their" raffle without being able to wander off to another organisations raffle. e.g. changing a4a_draw_view.php?editid1=2 to a4a_draw_view.php?editid1=3. I have created another field which is a random 8 character "reference" field, e.g. maT3cdG1

The first two fields of my table a4a_draw are a4a_draw_id int(11) which is a primary key primary key auto-increment and a4a_draw_ref chr(8). Upon creating a new record in the table a4a_draw, in the before add event, I create a random 8 character field and update a4a_draw_ref.

Can anyone point me in the right direction as what type of index and/or what url parameter to use – editid2 is not correct. This field was added later, but is positioned as the second in the mysql table.

Thanks in advance.

A
acpan 8/25/2021

if you want to use edit2, you need to set the field also as key column in the select field page. then your can refer to it as
https://a.b.com/a4a_draw_view.php?editid1=2&edit2=random_code

But i am not sure if user enters without the edit2 value, will it still display other data. If it works, you are done.

Else you can also restrict the access at View Page's Process Record Values event :

$code = isset($_REQUEST["code"]) ? $_REQUEST["code"] : -1 ;

if ( $code == -1 OR $values["a4a_draw_ref"] != $code) {
echo "Code not found!";
// or maybe redirect
return false;
}

Then give the URL with the "code" param to external party: https://a.b.com/a4a_draw_view.php?editid1=2&code=random_code

S
SteveDickson author 8/25/2021

Thanks for your reply. I modified it a bit to suit and all seems ok, however it still leaves me with the second stage of the problem (I thought fixing stage 1 would help me fix stage 2).

so the url looks something like this, a4a_draw_view.php?editid1=100&code=stuvwxyz, which presents a page which needs to have a link to

a4a_trans_add.php?mastertable=a4a_draw&masterkey1=100&code=stuvwxyz

I have set the hyprerlink in View As" in the field options as "./a4a_trans_add.php?mastertable=a4a_draw&code=". How do I get the masterkey1 value in there as well or just disregard the masterkey altogether?

A
acpan 8/25/2021

so the url looks something like this, a4a_draw_view.php?editid1=100&code=stuvwxyz, which presents a page which needs to have a link to a4a_trans_add.php?mastertable=a4a_draw&masterkey1=100&code=stuvwxyz

In View Page, for "View As", don't use hyprerlink, use custom code, you can ontain the master key this way:


// assume master key of a4a_draw is id
$url = "a4a_trans_add.php?mastertable=a4a_draw&masterkey1=".$data["id"]."&code=stuvwxyz";
$value = "<a href='$url' target='_BLANK'>Link</a>";


remove the target='_BLANK' to open in the same browser window.

Unless you programatically add the master key in the event code, disregard masterkey will add the data withinout linking to any particular draw, and becomes a mess later.

S
SteveDickson author 8/25/2021

A little bit more changing of quotes, etc and it worked a treat! Thank you so much. Would love to have someone like you around for when I struggle with these little (amd not so little) things. Happy to pay also. Please send me your details if you're keen. steve@coastalscales.com.au

A
acpan 8/25/2021

Glad it helps, no worries :) and good luck to your project !