if_POST然后执行命令或命令

I'm not good in PHP/HTML page. But I want to write script that allow me to do this :

If I typed something in box then the PHP/HTML file Execute Linux command for example :

 <form method='POST' name='name'><table width='100%' height='107' border='0'  id='Box'><tr>
      <td><input name='firstname' size='50' id="firstname" />
      </select></td>
    </tr>
    <tr>
      <td height='26' colspan='2'><input type='submit' value='DO' name='DO' id="DO" /></td>
    </tr>
    </table>
    </form>
<?php
if($_POST)
{ 
    $n = $_POST['firstname']);

echo exec(  command );
}
?>

I want to Execute this command

sshpass -p 'password' ssh -f   127.0.0.1 -l root -o StrictHostKeyChecking=no "./file.py  firstname  "
if (isset($_POST['firstname'])) {
  $command = "sshpass -p 'password' ssh -f   127.0.0.1 -l root -o StrictHostKeyChecking=no " . '"./file.py  ' . $_POST['firstname'] . '"';
  exec($command);
}

I would really suggest to check the content of $_POST['firstname'] for security reasons, but I guess you're aware of it. ;)

If you want to run the command at the same time you're writing you should use JavaScript, but if you want to run the command after you press the Submit button (the oned named DO), you should put your php code in a diferent file, lets call it runCommand.php, then in your form tag add the attribute action like this:

form action='runCommand.php' 

Along with the other attributes.