How do you "activate" a PHP script from a HTML file?
When the user clicks a link I need the PHP script to run.
July 29, 2010 | Filed Under Scripts FAQs
Comments
6 Responses to “How do you "activate" a PHP script from a HTML file?”
Powered by Yahoo! Answers
It depends
1) If you want to activate it based upon a form submission, make the action attribute of <form tag as your php script
2) If you want to be activated when you click a link, make it as href attribute of your HTML page.
Or you can use AJAX in your HTML page to run any PHP script on server.
to open in same window ::
<a href="open.php">Open Same Window</a>
to open in new window
<a href="open.php">Open New Window</a>
Xicroz Xadanz
Just make the link go to the php file.
<a href="myphpsrc.php">Click this link</a>
For PHP code to work you need to have the webpage renamed with a .php extension or else the code will not execute.
It would help if you gave a few more details here. There are many different ways to execute a script. You’ll most likely have to use an IF statement. For example, say we have a page called example.php with a link on it that automatically changes the background color, using a PHP program:
<html>
<body bgcolor="<?php echo $_GET['bg']; ?>">
<form name="bgcolor" method="get" action="example.php">
Please type a color or HEX code in the following box to change background:<br />
<input type="text" name="bg" />
</form>
</body>
</html>
I would suggest that you look up some PHP tutorials such as the excellent one found at http://www.w3schools.com/php/default.asp .
MKF is relatively correct, with the exception that that click on the link will completely refresh your page with the output of the Php script!
Remember that php runs and STAYS on the server. Its output IS an HTML page (with or without javascript included), so you can’t really "run a script" from the HTML sitting on the client’s side!
If you want to download a page, have a "link" to a php script, you have to use HTTPRequest to call that php script: that is made using the AJAX technique.
- You build your HTML page.
- In the page, you have an element with a name/id.
- A click on something will call a javascript function (already loaded on the client).
- That function will make an HTTPRequest to the server, to run the script/function
- The script will return an HTML "text" to update the Element…