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!

1
  • So what is your question...?? Where do you need help...?? Commented Oct 26, 2014 at 8:26

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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...
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: stackoverflow.com/questions/15594946/…
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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.