PHP reaction to user clicks

I’m a novice at programming, just started to dabble with PHP and a little JS.
I imagine this is a fairly basic thing to do but have not found any info on it yet, I have looked.
How to I get my PHP code to react to users clicking links on the page. For example if they click one link, it will set a variable to one value, if they click another it changes to a different value, or maybe execute a function.
Or is this something I would be better off doing with JS?

Hi
If you want the action after user clicks to be done without refreshing /open page, you need to use Ajax (JavaScript).
If you want that link to open s php file and send some value, define the link like this:
file.php?name=value

Then, in file.php get the value with: $val = $_GET[‘name’];

  • You can look on the net for: “php get post”.

Tanks for the answer.
I don’t want to refresh, so I think I will go with Ajax.
If I have a page with some embedded media, and I want to switch that media by clicking links on the page.
At present I have something that works, but it’s a messy workaround with an iframe targeted to other pages that contain just the embed code.
I have just changed the site from HTML to PHP and wondered if there was a smarter more efficient way to do this.

You can switch that media with JavaScript, changing the media file address in the “href” or “src” attribute of the html tag.
Exemple:

document.getElementById('embed_tag_id').src = 'other_scr_address';

Check out Cjax framework, which allows you to write Ajax code with PHP only.

I was about to say it would not be that simple, because of the nature of the embed code. The media is 360 panos from 360cities.net
The code I got at the time I wrote the page was an object with loads of params that made it work in both IE and FF. That was the reason I needed the workaround with other pages containing the code.
But going on 360cities today, the embed code they give you now is just an iframe with a src=“URL”, much simpler to work with :slight_smile: I may not even need scripting to do it now, though I will look at your suggestions, I do need to learn more scripting.