php include file

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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.
 
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');
}
?>
 
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.
 

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

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.
 
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?
 

punjabian263

Thread Starter
Joined
Mar 13, 2003
Messages
358
You have wrote already, this way.
Code:
<form action ="<?php echo $PHP_SELF; ?>" method="GET">
<input type="hidden" name="advanced" value="advance">
<input type="submit" value="Advanced-Search">
</form>

<?php
if (isset($_GET['advanced']))
{
  include('advanced_search.html');
}
?>
I want just similar like this against buttons, otherwise I will adopt as you say
button that links to another page with the proper contents?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Top