...

View Full Version : Execute function only if I click link



levani
09-13-2009, 03:40 PM
I have a standard php function which for example sends some data to database, but I don't want to execute this function every page load but only when I click a link on this page. How can I do that? How can I tell the function that the link is clicked?

Can anyone please help?

funnymoney
09-13-2009, 06:33 PM
two most common methods of this is by using POST or GET PHP predefined variables (http://us2.php.net/manual/en/reserved.variables.php).

GET is usualy used to comunicate with PHP with links, while POST is used to communicate with forms. Although you can also use GET with forms but that is not recommended.

Try this test.php to figure out how php works



<?php
if (isset($_GET['link'])) {
getFunction($_GET['link']);
}

if(isset($_POST['form'])) {
postFunction($_POST['form']);
}

function getFunction($variable) {
print $variable;
}

function postFunction($variable) {
print $variable;
}

?>

<a href="?link=test_link">Test link for get</a>
<br>
<form action="" method="post">
<input type="submit" name="form" value="Test link for post" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum