PHP Function On Link Click

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello guys,

I'm trying to get a PHP Function to start on a Link click, but I'm not sure how to do this.

I've tried putting "<a href="" onClick="<?php function(); ?>">Name</a>" but that doesn't work.
I've also tried putting "<a href="<?php function(); ?>">Name</a>" but neither does that.

Can someone please help me?
Thanks.
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
There was this one piece of code I used where I did this before, I just can't find it.

Oh well, I guess I'll just use that with AJAX.

Thanks (again) Holmes!
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Funny you should say that ecko, I found the file with it in and it's simply just: <a href="" onClick="<?php name(); ?>">Link</a>".
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,399
962
Funny you should say that ecko, I found the file with it in and it's simply just: <a href="" onClick="<?php name(); ?>">Link</a>".

It can't work that way because PHP is being executed on a server side and not on a client side like JS does.

u will have to use ajax. you cant execute a server side function called by a client side event handler – RPM Apr 12 '12 at 2:36

Where is your javascript ??? you can not call PHP form HTML events such as onClick ... you need AJAX to do the trick for you – Baba Apr 12 '12 at 2:37

This is PHP you're talking about, not ASP.NET. In PHP, there is no such thing as a button click event. PHP runs entirely on the server and has absolutely no knowledge of client-side events.
You're mixing up server side and client side coding. onclick is a Javascript trigger, that triggers a Javascript piece of code.
However, PHP is running on your server. So you need to call the PHP from your Javascript. There is a solution: AJAX. Look for some tutorials how to use them.
I can give more links if you'd like. Not to sound like a prude, but I use PHP everyday at work and think I know well more than the average user at DevBest.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,399
962
I shall video this for you.
What is a video going to prove? Post a live version of this with the source code. You can't place a function inside a client side onClick because the function is already parsed by the server.


You have #HTML #PHP in your signature. If you really knew anything about those two languages, you would already know you are wrong. HTML is rendered by the browser. PHP is executed by the web server.

This is the problem with kids being adamant that they are absolutely right. Even when given proof that they are wrong, their insecure ego refuses to succumb to such validations.
 

Users who are viewing this thread

Top