0

I have a webserver in Android using KSWEB application. It can support php, mysql, etc. I also have installed SL4A and python interpreter on my Android. I want to execute a python script (that runs on server side, the Android) on the click of a button.

All I have for now, is this:

<html>
    <head>
        <title>PHP Test</title>
    </head>
    <body>
        <button name=test>TEST</button>
    </body>
    <?php
        if(isset($_POST['test']))
        {
            exec('python test_andrei.py');
            echo ('Worked!');
        }
    ?>
</html>

Of course nothing happens when I click the button (both on server side (no script executed) and on client side (no echo output))... I am a complete noob in php and python...

Thank you for your help!

Vagabond
  • 877
  • 1
  • 10
  • 23

1 Answers1

0

First of all wrap the name value in quotes for the button:

<button name="test">TEST</button>

Secondly you need to wrap the button (and any other inputs) in a form for that isset($_POST['test']) to be submitted as expected:

<form method="post" action="<?php echo html_entities($_SERVER['PHP_SELF']); ?>">
    <button type="submit" name="test">TEST</button>
</form>

and also as you can see i added the action to the form so it submits to the same page

Kypros
  • 2,997
  • 5
  • 21
  • 27
  • 1
    Thank you for your quick reply, Kypros! Now the client side works (I receive the echo), but the server side still not functioning - the script is not executing... – Andrei Amariei Oct 26 '14 at 09:04
  • Although a different problem than this question, what is probably the reason is that you need the full path to the `python` executable. Accept this answer if it fixed your issue with forms and create a new one if you can't find the fix in my link. See here: http://stackoverflow.com/questions/15594946/python-script-failing-to-execute-from-php-exec – Kypros Oct 26 '14 at 09:26
  • I do no know the path of the python executable. I don't even know if I have to use python in the exec command. Besides that, things are different for Android and Linux... – Andrei Amariei Oct 26 '14 at 10:02