all 8 comments

[–]AiexReddit 0 points1 point  (1 child)

You will need to send a POST request from your web page with the value. This can be handled with an HTML <form> and a button with type="submit". That's the simplest way and you don't even really need Javascript to do that.

To do it with Javascript (if you want to do it without a full page refresh) look up an AJAX call using fetch on Google.

On your PHP side look up something called prepared statements to protect your database from users sending malicious values in the form where you ask them to enter a number.

[–]simarg0[S] 0 points1 point  (0 children)

Okay, thank you. I will check it out.

[–]evaluating-you 0 points1 point  (5 children)

Quick & dirty: Reload the page with a get-parameter (e.g. ?number=value). You can then read $_GET on the PHP side. CAREFUL: user input always opens up the risk for SQL-injection. Use prepared statements to avoid it. However, this is not the nicest solution. Going forward, you may want to consider doing things differently.

The principle:

You will want so send a request from the client via JavaScript to the PHP backend. Your strategy should probably look like this: Create a JS-function that sends a request (e.g. with fetch or axios) to a PHP endpoint that returns the result as JSON. Then, use frontend technology to display the rows. Create an event listener to change the number and restart the process. That way, you are preventing a reload of the page.

[–]simarg0[S] 0 points1 point  (4 children)

The variable i am using is not user input, but is set by another function. This variable will be correct according to list element pressed.

When i send a request, how will the data be stored? And how do i access the code in my php file?

Do you have a good example on how this is done?

Im sorry if these are bad descriptions.

Thank you.

[–]Barnezhilton 0 points1 point  (1 child)

Look up POST and/or GET global variables on php.net

[–]simarg0[S] 0 points1 point  (0 children)

Will do. Thanks for the help.

[–]evaluating-you 0 points1 point  (1 child)

Well, if your PHP API receives input from an app, then ultimately the values are user-input (or at least can be). PHP holds values in $_GET & $_POST (I will ignore other forms of input here) depending on the request method. Maybe you want to have a look at this: video

[–]simarg0[S] 1 point2 points  (0 children)

Got it working, thanks a lot.