Run PHP function from HREF link?

Hi

I have a page with an <A HREF ...> link on it. When the user clicks that link I want to execute a PHP function (which updates a database table), but I don't want to leave the page I am currently on ... how can I achieve this?

TIA

Martin
themitch2004Asked:
Who is Participating?
 
snoyes_jwCommented:
Use target="_blank" to set the link to open a new window, which calls the PHP page in question, or use AJAX, or submit a form on an hidden iframe.
0
 
themitch2004Author Commented:
Hi Snoyes

I like the idea of the new window, how can I resize the window that is opened from this link? Is this treated as a 'popup' (ie will popup blockers prevent the window opening)? What if the user has javascript disabled?

Thanks again.
Martin
0
 
BogoJokerCommented:
a target="_blank" should not be treated as a popup because the user clicked a link, its expected that something should and will happen.  On the other hand if you used window.open() to create a popup then it would most likely be blocked by a popup-blocker.

target="_blank" is not javascript, it is pure html in the <a> tag, so even if the user has javascript turned off it will work.

The thing is you cannot control the size of the window this way as far as I know.  If you do use javascript, you could control the size with a window.open() to make a popup.

Snoyes has some excellent suggestions.

Joe P
0
 
bgcboyusCommented:
You could just have the link direct them to click.php which records the cilck them do a header redirect to direct them to were you wish them to go or (go back)

click.php

<?

//record the click

header("Location:" .  $_SERVER['HTTP_REFERER']);
?>
0
 
BogoJokerCommented:
Snoyes first post mentions target="_blank".  I just clarified some questions the author had after hearing it from snoyes.  He probably deserves the points.  Or at least a split.

Joe P
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.