0

I've basically have a string a user can input and hit "Send". Then this string variable should be passed to another page that opens. I've tried using session, but it doesn't work (the second page doesn't load). Here's my code:

First page.

<?php
    session_start();
    echo "<input type=\"text\" id=\"myText\">";
    echo "<button onclick=\"submit()\">Submit</button>";

    $_SESSION['userInput'] = $input;
?>
<script type="text/javascript">
    var submit = function() {
        input = document.getElementById("myText").value;
        window.open ('runSecond.php','_self',false);}   
</script>

Second page.

<?php
    session_start();
    $input = $_SESSION['userInput'];
    system('./myPythonScript.py ' $input);
?>
1
  • What is the value of $input in the first page? Commented Jan 20, 2017 at 21:25

1 Answer 1

1

Page 1

 <?php
        session_start();
        echo "<input type=\"text\" id=\"myText\">";
        echo "<button onclick=\"submit()\">Submit</button>";

        $_SESSION['userInput'] = $input;
    ?>
    <script type="text/javascript">
        var submit = function() {
            input = document.getElementById("myText").value;
            window.open ('runSecond.php?userInput=' + input,'_self',false);}   
    </script>

Page 2

<?php
    session_start();
    $input = $_GET['userInput'];
    system('./myPythonScript.py ' $input);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Use form and get rid of the javascript code would be better. No?
@ibrahimmahrir using a form is the obvious choice. I don't know his use case so i just fixed his code

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.