Skip to content
Advertisement

Executing Python Script with PHP Variables

I am writing a simple application that uses information from a form, passes it through $_POST to a PHP script that executes a python script and outputs the results. The problem I am having is that my python script is not actually running with the arguments being passed in.

process3.php file:

JavaScript

Output:

JavaScript

At the top of my wordgame2.py, I have the following (for debugging purposes):

JavaScript

Why isn’t the number of arguments being passed = 3? (Yes, my form does send the data correctly.)

Any help is greatly appreciated!

Edit: I might add that it does run when I explicitly tell it the start and end word… something like this:

JavaScript

Advertisement

Answer

Update –

Now that I am aware of PHP, the mistake lies in using the single-quotes '. In PHP, single quoted strings are considered literals, PHP does not evaluate the content inside it. However, double quoted " strings are evaluated and would work as you are expecting them to. This is beautifully summarized in this SO answer. In our case,

JavaScript

would work, but the following won’t –

JavaScript

Original answer –

I think the mistake lies in

JavaScript

Try this

JavaScript
Advertisement