Page 1 of 1

executing a php function from either html or java script

Posted: Tue Oct 09, 2007 9:06 pm
by kinga
Hey guys,

i am trying to make a button that will execute a php function that i have in the same page.
Can some please give me an example of how to do this?

Thanks,
Kinga

Posted: Wed Oct 10, 2007 5:20 am
by lettie_dude
Place the following in the form tag:

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
This will submit the page to itself.

Then add your function code to the top of the page.

Wrap this in something like:

Code: Select all

if(isset($_POST['submit'])) {

// Your code

}
Then the code will only process when the submit button or whatever you call it is actioned.

Posted: Wed Oct 10, 2007 11:47 am
by feyd
Never ever ever ever ever ever ever use PHP_SELF.

We've talked about it enough that searching should tell you why.