Re: how to call a function when somebody click a link?



[Taking a step back]

I think it'd help if the OP says why they want to do all this. If I
ever have trouble doing something I usually find that I am trying to
fit a square peg in a round hole and I need to approach the problem in
a different way.

But, given what we know, it looks like the OP needs one HTML page with
some PHP at the top. Like:

HTML headers
<?php
if (isset($_REQUEST['dofunction'])) {
function();
}
?>
rest of the HTML page including:
<a href="<?php echo $_SERVER['PHP_SELF'].'?dofunction'; ?>">click
here</a>




On 4 Nov 2006 02:45:15 -0800, "Mateusz Markowski"
<mateusz@xxxxxxxxxxx> wrote:

Paste the code that you think may give parse error.

yangsuli@xxxxxxxxx napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.

yangsuli@xxxxxxxxx napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
yangsuli@xxxxxxxxx napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link


then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.location.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(


now i am thinking using a flag,say,$functioncall,
href=$_server[request_url]&functioncall=1
then if functioncall==1,call that function
but is it right?
is there some way simple to do that?


PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call=helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
.



Relevant Pages

  • Re: how to run scripts after a page has already loaded and been sent to a users browser?
    ... > It's because PHP is a server side scripting language, ... > do stuff before you send stuff to user's web browser. ... As we've discussed on this newsgroup before, if a script starts ... that is after the last HTML is sent to a web browser. ...
    (alt.php)
  • Re: HELP - Cant change Include Path
    ... Here is my php.ini path for the php.ini in both php and sql dirs: ... which did work on the remote linux server and sent me some mail ... Although my gmail acct picked the mail up as ... an attachment instead of as html - but gmail is really wierd about ...
    (comp.lang.php)
  • Re: How do I get HTML sent to server?
    ... sees in a client browser. ... html does only approximately show how different browsers, ... html is available on the server and can be directly taken from the ... html does not show the changes made to the DOM on the browser. ...
    (comp.lang.javascript)
  • Re: PHP-Yes, HTML-No --- Why?
    ... You are arguing to have .html at the end of every URL even if the file contains PHP or another scripting language. ... We are talking about web servers, not FTP servers. ... I never said the server should parse MP3 files or whatever, ...
    (comp.lang.php)
  • Re: How do I get HTML sent to server?
    ... sees in a client browser. ... html does only approximately show how different browsers, ... html is available on the server and can be directly taken from the server ... html does not show the changes made to the DOM on the browser. ...
    (comp.lang.javascript)