Html button in PHP calling PHP function?

morning to all,
ive never tried to do this so don’t even know if PHP does this or not:

i have a php script and this is how it ends:
print"<center><br><table width=\“100%\” border=\“0\”>
<tr>
<td width=\“100%\” height=\“1%\” bgcolor=\“#FF9900\”>
<div align=\“right\”><input type=\“submit\” name=\“Modify\” value=\“Modify\”>  
<input type=\“submit\” name=\“Submit\” value=\“Submit\”></div>
</td>
</tr></table>";
?>

basically, this page redisplays the info that the user input in the form before this page…it asks them to verify the info and if something is wrong, to click on the Modify.

My situation: I want it so that if the user clicks on Modify, a PHP script is run that will clear certain values (the point being, some PHP script to simply run on the click of Modify and another to run on click on Submit).

How do you make it so that you integrate HTML Form buttons (as above) that are created in a PHP script to run PHP scripts based on which button is clicked on? (kinda like: if MODIFY is clicked, do this PHP script, if SUBMIT, do this…oh yeah, and I don’t want to call another PHP file, just want to run a script within this file, before the ?>)

Any help would be great! thank you.



if( isset( $_REQUEST['modify'] ))
{
// insert code here...
}

if( isset( $_REQUEST['ok'] ))
{
// insert code here...
}



<form>
<input type="submit" name="modify" value="Modify" />
<br />
<input type="submit" name="ok" value="OK" />
</form>

hey gasolene,

thanks for the quick response…i didn’t know that PHP could do that!
now, if the user clicks on Modify or Submit, how can I make it so that after the PHP script is executed (in one of the “insert code here” sections that u mentioned below) the person is taken to another page?

For example, when the user clicks on Modify, I will be deleting some files (which I know how to do) and then I need to take them back to the form that they just came from, have it be filled with the same info that was on the review page and allow them to modify their input.

Any thoughts??

Thanks again!

that depends on how you got the values on the review page,


  header('location:mypage.php'); // this redirects to other page

how did you populate the values on the rewview page??

“oh yeah, and I don’t want to call another PHP file, just want to run a script within this file, before the ?>”

Well, you can make it so that the form calls itself and then handles the form data depending on which button you pressed, but you will have to make another call to the web server. You can’t just run a script within the current php page, because once the page is loaded in your browser there’s no longer any actual php code in it. The PHP code stays on the server and is parsed before you actually see the page.

So what you want to do is add some code in your page that checks to see if a certain variable has been set. – pretty much what Gasoline posted. But for it to work the form will have to post the data to itself (the current php page).

The easiest way to do this is to set the “action” attribute of the form tag to:



action="<?php echo $_SERVER['PHP_SELF']; ?>"


When the page is loaded it will fill in that attribute with whatever the current page is.

Hopefully that makes sense…