1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

php include file

Discussion in 'Software Development' started by punjabian263, Apr 22, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    how i can include file against a button, as when i press the button a file should be include,
    e.g
    Code:
    echo "<button onclick=advance.php>advance search</button>";
    but this not works
     
  2. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    HTML and JavaScript run on the client. PHP runs on the server. They can not directly communicate, if you want to include() when a button is clicked, the button must submit a form to a PHP script which then includes the file.
     
  3. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    please give me example
    thanks
     
  4. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Code:
    <form action ="<?php echo $PHP_SELF; ?>" method="GET">
    <input type="hidden" name="advanced" value="advance">
    <input type="submit" value="Advanced-Search">
    </form>
    
    Code:
    <?php
    if (isset($_GET['advanced']))
    {
      include('advanced_search.html');
    }
    ?>
    
     
  5. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    brendandonhu thank you
     
  6. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    No problem :)

    BTW you could do this with a little javascript, and a hidden DIV or SPAN. It wouldn't work in some browsers though.
     
  7. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    hello brendandonhu, i need some help here, i want to display some button, and will include a file against that button, e.g
    Code:
    <form action ="<?php echo $PHP_SELF; ?>" method="GET"><table bgcolor=#ff5555 ><tr ><td>
    <input type=button value="flight no" name="flight"></td><td>
    <input type=button value="departure place" name="departure"></td><td>
    <input type=button value="arrival place" name="arrival"></td><td>
    </form>
    
    how i can manage it.
     
  8. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Code:
    <?php
    if (isset($_POST['flight']))
    {
    include('flight.html');
    }
    ?>
    
    Just do that for each form field.
     
  9. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    Code:
    <?php 
        if (isset($_GET['flight'])): 
        include 'advance.php'; 
        elseif (isset($_GET['departure'])): 
        include 'index.php'; 
        else:     
    ?> 
    <form action ="<?php echo $PHP_SELF; ?>" method="GET">
    <table bgcolor="#ff5555"> 
    <tr> 
        <td><input type="submit" value="flight no" name="flight"></td> 
        <td><input type="submit" value="departure place" name="departure"></td> 
        <td><input type="submit" value="arrival place" name="arrival"></td> 
    </tr> 
    </form> 
    <?php 
    endif; 
    ?>
    
    this code overwrites the button's page, but I want to include the page, mean add contents in button's page not overwrite.
     
  10. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    PHP runs on the server, it can not just modify the current document.
    For what you want, why not just have a button that links to another page with the proper contents?
     
  11. punjabian263

    punjabian263 Thread Starter

    Joined:
    Mar 13, 2003
    Messages:
    358
    You have wrote already, this way.
    I want just similar like this against buttons, otherwise I will adopt as you say
     
  12. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/222821

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice