-1

I have a select tag with some options and trying run a query based on a selected option.

My book.php contains the select tag with option and course.php will check the selected option and execute the appropriate query.

The problem I am facing is that course.php does not do what it spouse to and throws an error when i run it. I would like to find out where am going wrong with it and if the logic is correct.

book.php:

<div class="input-wrapper">

        <?php require "course.php" ?>

            <select id="workshop" name="workshop" onchange="return test();">
                <option value="">Please select a Workshop</option>
                <option value="Forex">Forex</option>
                <option value="BinaryOptions">Binary Options</option>
            </select>

            <select id="Forex" name="Forex" style="display: none">
                <option value="">Please select a date</option>
                <option value="01/01/01">01/01/01 at 6.30pm</option>
                <option value="02/02/02">01/01/01 at 6.30pm</option>
                <option value="03/03/03">01/01/01 at 6.30pm</option>
            </select>

            <select id="Binary" name="Binary" style="display: none">
                <option value="">Please select a date</option>
                <option value="01/01/01">01/01/01 at 6.30pm</option>
            </select>

        </div>

course.php:

    $form = Array();

$form['workshop'] = $_POST['workshop'];
$form['forex'] = $_POST['Forex'];
$form['binary'] = $_POST['Binary'];

//Retrieve Binary Workshops 
if($form['workshop'] == 'Forex'){
    $sql = "SELECT id, course, location FROM courses WHERE course LIKE '%Binary%' OR course LIKE '%binary%'";
    $query = mysqli_query($link, $sql);
        while($result = mysqli_fetch_assoc($query)){
            print_r($result);echo '</br>';

        }
    }else{
        $sql2 = "SELECT id, course, location FROM courses WHERE course LIKE '%Forex%' OR  course LIKE '&forex%'";
        $query2 = mysqli_query($link, $sql2);
            while($result2 = mysqli_fetch_assoc($query2)){
                print_r($result2);echo '</br>';
        }
    }

error: Notice: Undefined index: workshop in C:\xampp\htdocs\opes\course.php on line 11

Notice: Undefined index: Forex in C:\xampp\htdocs\opes\course.php on line 12

Tomazi
  • 781
  • 9
  • 27
  • 46
  • *"throws an error"* That's amazing. – AbraCadaver Dec 17 '13 at 16:20
  • You can't access array values until they exist. – John Conde Dec 17 '13 at 16:22
  • Even if i dont us an array and simply assign $_POST results to different variables i get the same error – Tomazi Dec 17 '13 at 16:27
  • 1
    No post data exists until a post request is made to the server for the course.php page. Including it in the page with the selects will not give that page access to php $_POST vars because no data exists in the $_POST var unless you submit a form(using post method) or post request to the given php page. – elitechief21 Dec 17 '13 at 16:37

1 Answers1

0

OK guys I mnaged to fix the problem works great what i did is added

if(isset($_POST['workshop'])){

}

Thanks for trying to help me regards

Tomazi
  • 781
  • 9
  • 27
  • 46