Jump to content

[SOLVED] Multiple Drop Down, convert from php 4 to 5?


aeafisme23

Recommended Posts

Hey guys, i have came to the conclusion that this used to work on PHP 4 and when i upgraded to PHP 5 it said something along the lines that "you should have learned to code right noob". Ha, not really, here is the error i get:

 

PHP Notice: Undefined variable: sel in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 101 PHP Notice: Undefined variable: sel in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 101 PHP Notice: Undefined variable: sel in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 101 PHP Notice: Undefined variable: sel in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 101 PHP Notice: Undefined variable: sel in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 101 

 

URL, http://www.livingwellsanctuary.com/sproductline/singingbowls/crownchakra.php you can choose 2 options but the 3rd one errors, see for yourself!

 

That is pointing at this line

echo "<option value='$v' $sel>$t</option>";

 

Anyways i will provide the necessary code. My first impression was to add this to the top of the page to declare the variables, but i just got so "MANY" errors.

 

$t= $_GET['t'];
$v= $_GET['v'];  // ETC..... just declaring some of the variables used in this but not really sure if i need to do this or which ones to declare

 

It would be very helpful if i could get some insight to what direction i need to go. Thank you.

 

 

PHP PAGE

<?php

$allOpts = array(
          '8B'  => '8" B Chakra Bowl',
          '10B' => '10" B Chakra Bowl',
          '12B' => '12" B Chakra Bowl',
          '13B' => '13" B Chakra Bowl',
          '14B' => '14" B Chakra Bowl',
          '15B' => '15" B Chakra Bowl',
          '16B' => '16" B Chakra Bowl'
);

function makeSelect1($opts, $currVal) {
        echo "<SELECT name='option1' onchange='this.form.submit()'>";
        echo "<option value=''>- select 1st choice -</option>";
        foreach ($opts as $v => $t) {
                 // which option is selected?
                 $sel = $v==$currVal ? 'selected' : '';
                 echo "<option value='$v' $sel>$t</option>";
        }
        echo '</SELECT><br><br>';
}

function makeSelect2($opts, $currVal, $opt1) {
        echo "<SELECT name='option2' onchange='this.form.submit()'>";
        echo "<option value=''>- select 2nd choice -</option>";
        if ($opt1) {
            unset($opts[$opt1]); //remove 1st choice
            foreach ($opts as $v => $t) {
                     // which option is selected?
                     $sel = $v==$currVal ? 'selected' : '';
                     echo "<option value='$v' $sel>$t</option>";
            }
        }
        echo '</SELECT><br><br>';
}

function makeSelect3($opts, $opt1, $opt2) {
        echo "<SELECT name='option3' onchange='this.form.submit()'>";
        echo "<option value=''>- select 3rd choice -</option>";
        if ($opt1 && $opt2) {
            unset($opts[$opt1]); //remove 1st choice
            unset($opts[$opt2]); //remove 2nd choice
            foreach ($opts as $v => $t) {
                     echo "<option value='$v' $sel>$t</option>";
            }
        }
        echo '</SELECT>';
}

?>


<?php
$option1 = isset($_GET['option1']) ? $_GET['option1'] : '';
$option2 = isset($_GET['option2']) ? $_GET['option2'] : '';
$option3 = isset($_GET['option3']) ? $_GET['option3'] : '';

if ($option1 && $option2 && $option3) {
   echo "1st choice : $option1<br>";
   echo "2nd choice : $option2<br>";
   echo "3rd choice : $option3<br>";
   echo "<br>";
   require("resultscrown.php");
}
else {
   echo "<FORM name='form1' method='GET'>";
   makeSelect1($allOpts, $option1);
   makeSelect2($allOpts, $option2, $option1);
   makeSelect3($allOpts, $option1, $option2);
   echo '</FORM>';
}
?><a href="<?php echo "{$_SERVER['PHP_SELF']}"?>?option1=&option2=">Reset Selections</a>

 

This is above in the code, but its showing that if the above shows a value for all 3 options then it requires the information on resultscrown.php which is all good. Or just use this url which is testing the query string to make sure it can pull from file http://www.livingwellsanctuary.com/sproductline/singingbowls/crownchakra.php?option1=8B&option2=10B&option3=12B

 

if ($option1 && $option2 && $option3) {
   echo "1st choice : $option1<br>";
   echo "2nd choice : $option2<br>";
   echo "3rd choice : $option3<br>";
   echo "<br>";
   require("resultscrown.php");

 

Link to comment
Share on other sites

Im not sure i entirely follow your code, but the problem is that $sel is never defined in your makeSelect3 function. If this was working correctly prior to the upgrade, i suggest you remove the reference to it:

 

<?php
function makeSelect3($opts, $opt1, $opt2) {
        echo "<SELECT name='option3' onchange='this.form.submit()'>";
        echo "<option value=''>- select 3rd choice -</option>";
        if ($opt1 && $opt2) {
            unset($opts[$opt1]); //remove 1st choice
            unset($opts[$opt2]); //remove 2nd choice
            foreach ($opts as $v => $t) {
                     echo "<option value='$v'>$t</option>";
            }
        }
        echo '</SELECT>';
}
?>

Link to comment
Share on other sites

Ya i thought the same thing but when i did that i received this error

PHP Notice: Undefined variable: currVal in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 102 PHP Notice: Undefined variable: currVal in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 102 PHP Notice: Undefined variable: currVal in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 102 PHP Notice: Undefined variable: currVal in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 102 PHP Notice: Undefined variable: currVal in E:\Domains\livingwellsanctuary.com\wwwroot\sproductline\singingbowls\crownchakra.php on line 102 

which just points to that line. It's accepting the first two options, but something is definitely iffy on the 3rd.

Link to comment
Share on other sites

*bump

 

I am really avoiding going the database route, i found this http://www.plus2net.com/php_tutorial/dd3.php but it uses a database. Should i stick with my original code? I just don't understand why the 3rd select will not work.

 

Ive tried the following:

 

ADDED the SEL part for the 3rd select:

 

function makeSelect3($opts, $opt1, $opt2) {
        echo "<SELECT name='option3' onchange='this.form.submit()'>";
        echo "<option value=''>- select 3rd choice -</option>";
        if ($opt1 && $opt2) {
            unset($opts[$opt1]); //remove 1st choice
            unset($opts[$opt2]); //remove 2nd choice
            foreach ($opts as $v => $t) {
                     // which option is selected?
                     $sel = $v==$currVal ? 'selected' : '';

                     echo "<option value='$v' $sel>$t</option>";
            }
        }
        echo '</SELECT>'; 

 

Ive tried rearranging

function makeSelect3($opts, $opt1, $opt2) {

to

function makeSelect3($opts, $opt1, $currVal) {

etc...

 

ive also tried adding

<?php 
$option1 = $_GET['option1'];
$option2 = $_GET['option2'];
$option3 = $_GET['option3'];
?>

into the required file.

 

Thanks again

 

Link to comment
Share on other sites

The reason why it now works is that you're no longer trying to make use of a variable that hasn't been previously defined.

 

The reason why it worked with php4 was that it was setup to ignore notices. That is, the error was still there, but PHP can deal with it. It tends to lend to messy code and can make typos much harder to find though, so it's generally better to work with notices on.

 

I guessed that it was not needed since the code previously did what was expected, whilst dealing with the error itself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.