-1

So when I load my HTML page, it automatically runs the exec() command by default. How do I make it so like when it only runs when I press the submit button and not my default?

<form action="site.php" method="POST">

  <input type="text" id="fname" name="fname"><br><br> 
  <input type="text" id="lname" name="lname"><br><br> 

  <input type="submit" value="Show values">

</form>

</body>
</html>

<?php

exec('java -jar "C:\temp\test.jar" -db dbs.zed.bvba.com -h 10.222.222.22 -new 1', $response);
print nl2br(print_r($response, true));

?>
Ivar
  • 6,138
  • 12
  • 49
  • 61
dxdiag
  • 1
  • 6
  • 1
    Does this answer your question? [Calling a particular PHP function on form submit](https://stackoverflow.com/questions/12328354/calling-a-particular-php-function-on-form-submit) – Ivar Mar 04 '20 at 12:23
  • You should be _very_ careful when using `exec()`, especially when you are passing user/form input to it. Using it incorrectly could allow people to fully compromise your server. – Ivar Mar 04 '20 at 12:27

1 Answers1

0

You have to check, the form is submitted or not.

<?php 
if(isset($_POST['submit']))
{
   exec('java -jar "C:\temp\test.jar" -db dbs.zed.bvba.com -h 10.222.222.22 -new 1', $response);
   print nl2br(print_r($response, true));
}

?> 
Shubham Azad
  • 786
  • 2
  • 10
  • 25