How do you "activate" a PHP script from a HTML file?

When the user clicks a link I need the PHP script to run.


Comments

6 Responses to “How do you "activate" a PHP script from a HTML file?”

  1. Atif Majid on July 29th, 2010 2:16 pm

    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.

  2. Xicroz Xadanz on July 29th, 2010 2:16 pm

    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

  3. MyKidsFan on July 29th, 2010 2:16 pm

    Just make the link go to the php file.
    <a href="myphpsrc.php">Click this link</a>

  4. Jamie on July 29th, 2010 2:16 pm

    For PHP code to work you need to have the webpage renamed with a .php extension or else the code will not execute.

  5. J.J.'s Advice / Avis de J.J. on July 29th, 2010 2:16 pm

    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 .

  6. just "JR" on July 29th, 2010 2:16 pm

    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…

Powered by Yahoo! Answers