Using sessions issue

I’m having problems with obtaining a value that starts as URL parameter.

I have a form on a page that is accessed by a url that has a parameter - product_id. I have used ‘Session storage manager to save this value in a Browser session. ( See screen shot )

I need to use this value in the page that the form re-directs to. I need to use the value in a Server action. My understanding is I need to define the session… BUT WHERE?. I see I can define it from Globals/input/$_SESSION, but I can also define a session from API/input/$_SESSION. ( See screen shots )

So this is confusing me. The purpose of this is I need to use it in a database query as a condition value ( see screen shots )

and then values in from that query to be used in the Data insert below it. ( see screen shot )

In the API action for the starter page I have used a set session to capture the value but i’m not sure this is correct.

I hope this make sense.

Thanks in advance!

Hi Steven

A client-side session and a server-side session are different sessions. To get the value from the client side to the server, you need to use the POST or GET method, and only then you can use this value on the server side.

Thanks for your response @Mr.Rubi. So can you explain how I’m supposed to achieve my goal.
Further to my previous attempts this is what I have so far.

the url to the starter page could be rtm-application-form.php?product=1
from the App structure I Define query params’ and name the query productID

I then add Session storage manager to the app structure and added a new variable with the same name.

Then from the form submit button I add a Run action to the inline flow and set the session value to the query variable.

Now when the page is submitted and re-directed to the next page. I can add the session storage manager to the page and add the same variable productID and use it in the page. I’ve tried this and it works fine.

But I need to get this value and use it in the condition in the Database query…

…to have the right values used in the Data insert below it.
I just can’t work out how i can do this within wappler.

I think you are really trying to overcomplicate things here.
Is all what you need to do - send the ?product=1 value on form submit to your server action?

thanks @Teodor I thought I might be. So i’m not sure how I grab the param’ value and send to server action. Can you elaborate?

You don’t need sessions for that.
All you need is a hidden field in your form, which gets a dynamic value of dmx-bind:value="query.product" and it will post the value of the query parameter named product to your server action.

So i’ve got my hidden field in the form on the first page.

<input type="hidden" name="product_id" id="product-id" value="" dmx-bind:value="query.productID">

So now I go to the Data query on the next page where I need to use the value… How do use it in the query condition?

Probably I don’t really understand what are you trying to do. Are you using two pages? What for / how?

Yes there’s two pages. You might remember I setup a multi-step form which is an application form. This page is directed to by the url rtm-application-form.php?productID=1 The productID value is variable depending on different types of application we have. The value relates to the item previously created in this DB table. so productID = item_id

When this form is submitted it re-directs to the account set-up page which will be user-registration.
The details from this form gets inserted into this table. where I also need to insert the productID value into

Hope this makes sense!

sorry had to take down screenshot because of email adresses

You can use session variable to pass the value after insert on page 1 then do redirect to page 2.
On the page 2 just use the session variable value to filter your server action using a GET variable.

To do what you want, you need to create a variable in the GET parameters that you will use for filtering:

After that, on the client side, you will have this field in the request settings:

Insert the values from the session parameter on the client side there.

Sound easy in theory but where I’m struggling is performing this in wappler. I’m just not fully understanding the interface. It’s not straight forward for us mere beginners.

@Teodor @Mr.Rubi i’m pulling my hair out with this.
So this is what i’ve got…

Hidden field in form on first page:
<input type="hidden" name="product_id" id="product-id" value="" dmx-bind:value="query.productID">

I then go to the API action in the second page and the GET variable product_id i’m using the input name from the hidden field. Is this correct?

I then go to server connect properties where I need to pick the value for the input parameter . There’s two possible options here… Query/productID or Session Storage manager/data/productID… I’ve tried both and neither work!!
Assuming a get the above value correct eventually…

So then I got to the data query on and use the GET value in the Condition.

So where am I going wrong here?

Thanks in advance.

Steven, I think you've mixed up two different approaches a bit.

In your case, you can not use the hidden input at all.

So, on your server side, everything looks right from the video.

What do you need to do on the client side:

  1. First you have to repeat the steps that you have already done before:
  1. Then you go to the second page and make the following settings there:

The data must be used from Session Storage manager/data/ProductID. You write above that it doesn't work. Perhaps because you didn't perform the setings specified in step 1 beforehand?

The logic of the work should be like this. When you go to the first page on the client side, the value is stored in the ProductID session variable. Then, when you go to the second page and the session variable takes this value and is used as an input parameter for Server Connect. On the server, this parameter is used to filter the database query.

Really appreciate your help @Mr.Rubi … Yes i’m getting in a right muddle :laughing: … I’ll go again with your input and see how i get on! … Many thanks!

I must be missing something really stupid here @Mr.Rubi. So changed all the variable names and the parameter to product I guess for the reason I thought I might be getting using wrong values in places as some where product_id and some were producID. So now I have this.

URL to page1 = rtm-application-form.php?product=1

On Page 1:

1.Define query paramater

  1. Define session in storage manager

  1. I then set the click event / inline flow in the Submit button.

So then on to Page 2:

  1. I create a variable in Session storage manager the same as page 1 ( Not sure if this is necessary )

  2. Add a server connect component and select the API action for page 2.

  3. Then select the value form the picker for Session Storage Manager/data/product

  4. The in server connect API action for page 2. I go into the data query, go to the conditions and select the GET value

  1. I then go to the Data Insert below it and bind the query values I need to the DB table

Thats it. So the query values used in the Data insert aren’t sending values to the database. So I must be missing something. :tired_face: :sob:

This is where you insert product[0].item_id and product[0].item_type. This record will take only one value of item_id and item_type, the very first one under index 0, which the product query will return, even if there are several records. Is this happening? Is there data there?

Please show the settings in these steps:

Also, judging by the final task that you want to achieve, it is more appropriate to use the method proposed by Teodor with a hidden input. But in order not to confuse you even more, let’s first figure out the method using the session variable, and then we’ll figure out the way in which you can send the productID in the form using a hidden input.

Here’s server connect component settings.

So my Data Query uses the condition - products.item_id equal $_GET.product

It queries this table ( here’s the first few data rows )

So the standard item is item 1 so thats the value used in the url parameter. Subsequently the value being stored in the GET variable. So the row i want returning in this instance is row 1. But let’s say the item_id passed in the URL parameter is ?product=9 then it would be item_id 9 in the table that is filtered in the query.

This is right isn’t it?

So maybe I’m not understanding this [0] index in the binding??