0

I have two dropdown boxes and I want the user to choose values from both. The dropdown boxes are filled with results of a query on page load. I want these values to then be stored as a session variable for use in subsequent queries.

First file = choose.php

<html>
    <form action="choose2.php" method="post">
    <?//db connection stuff taken out from here
        }
// fill classes      
    $result = mysqli_query($con,"SELECT * FROM classes");                                            
    echo "<select id='classlist'>";

    while($row = mysqli_fetch_array($result))
        {
        echo " <option value=" . $row['id'] . ">" . $row['classname'] . "</option>";
        }
    echo "</select>";

    //fill schemes of work
    $result = mysqli_query($con,"SELECT * FROM schemes_of_work");
    echo "<select id='sowlist'>";

    while($row = mysqli_fetch_array($result))
        {
        echo " <option value=" . $row['id'] . ">" . $row['name'] . "</option>";
        }
    echo "</select>";

    mysqli_close($con);
    ?>   
<input type="submit">
</form> 
</html>

second file = choose2.php

 <?php  session_start(); 
    $_SESSION['classname'] = $_POST["classlist"];
    $_SESSION['sowname'] = $_POST["sowlist"];
    ?>

    <?php echo $_SESSION['classname'];?>
    <?php echo $_SESSION['sowname'];?>

I cant get this to work though - I am getting an empty page on choose2 and the following error in apache log: "Undefined index: sowlist in /var/www/assessment/choose2.php on line 3,

2
  • var_dump() your session array after session_start() in choose2.php to see what you do have Commented Jul 24, 2013 at 11:42
  • He will have null most likely, since no post is received. Commented Jul 24, 2013 at 11:43

1 Answer 1

2

The select tag should have a name attribute to be able to use it in php POST. Try

<select id='classlist' name="classlist">

The same for the other one.

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

Comments

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.