Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:11:35+00:00 2026-06-14T04:11:35+00:00

Hi I’m trying to run two PHP functions from one program which are executed

  • 0

Hi I’m trying to run two PHP functions from one program which are executed by pressing two html form inputs, A table with 2 buttons, Start and Remove; Start writes a file ‘ON’ and Remove writes a file ‘OFF’ but at the moment when i click both of the buttons in runs the php scripts with both out puts as OFF please Help!


The table with the buttons.

<html>
<TABLE BORDER="3" CELLPADDING="0" CELLSPACING="10">
<TD>
<table BORDER="3" CELLPADDING="3" CELLSPACING="3">
           <TH>Socket 1</th>
           <TR></tr>
           <TD>Serial Number</TD> <TD>ON/OFF</TD>
           <TR></TR>
           <TD>Elapsed Time </TD> 
           <TD><?php
                 include_once ("statusfileon.php")         
                     ?></TD> 
           <TD><?php 
                 include_once ("statusfileoff.php")         
                     ?></td>
           <TR></TR>
           </TABLE>
</TD>
<TD>
<table BORDER="3" CELLPADDING="3" CELLSPACING="3">
           <TH>Socket 2</th>
           <TR></tr>
           <TD>Serial Number</TD> <TD>ON/OFF</TD>
           <TR></TR>
           <TD>Elapsed Time</TD> <TD>Start</TD> <TD>Remove</td>
           <TR></TR>
           </TABLE> 
</TD>
</TABLE>
</html>

Satusfileon.php

<?php // statusfileon.php
      //Write file if button is clicked
      if(isset($_POST['submit'])) {
               statusfileon();
}
?>
<?php //Write file function
function statusfileon(){ //File function name.
$fh = fopen("statusfile.txt", 'w') or die("Fail to create file");
//Text which is displayed in file (on).
$text = <<<_END
on
_END;
fwrite($fh, $text) or die("Could not write to file"); // If file location could not be found file isn't writen.
fclose($fh); //Close file.
}
?>
<html>
   <!--Button and variable for file permission. -->
    <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
     <input type="submit" name="submit" value="Start">
      </form>
</html>

statusfileoff.php

<?php // statusfileoff.php
      //Write file if button is clicked.
      if(isset($_POST['submit'])) {
               statusfileoff();
}
?>
<?php //Write file function 
function statusfileoff(){ //File function name.
$fh = fopen("statusfile.txt", 'w') or die("Fail to create file");
//Text which is displayed in file (off).
$text = <<<_END
off 
_END;
fwrite($fh, $text) or die("Could not write to file"); // If file location could not be found file isn't writen.
fclose($fh); //Close file.
}
?>
<html>
   <!--Button and variable for file permission. -->
    <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
     <input type="submit" name="submit" value="Remove">
      </form>
</html>

Any help would gladly be appreciated as I’m new to programming please excuse any bad practices
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:11:36+00:00Added an answer on June 14, 2026 at 4:11 am
      <TD><?php
           include_once ("statusfileon.php")         
      ?></TD> 
           <TD><?php 
                 include_once ("statusfileoff.php")         
      ?></td>
    

    PHP is executed by the server before the HTML is served up. So it isn’t like clicking the buttons is calling your PHP function.

    In this case, statusfileon() is executed and right afterwards, statusfileoff() is executed and then the page is served to your browser. Button clicks aren’t doing anything.


    To execute the code, you might want to redirect the user to statusfileon.php or statusfileoff.php on click of the button using an HTML link if you want the behaviour you are looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.