aeafisme23 Posted April 4, 2008 Share Posted April 4, 2008 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"); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
aeafisme23 Posted April 4, 2008 Author Share Posted April 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
aeafisme23 Posted April 4, 2008 Author Share Posted April 4, 2008 *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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 I think you just need to remove all reference to $sel in makeSelect3. Did you try the version of the function that i posted? Quote Link to comment Share on other sites More sharing options...
aeafisme23 Posted April 4, 2008 Author Share Posted April 4, 2008 Thanks ginger, you would think i would actually just copy your code and instead i just replaced what i thought you meant in the function, it works heh. I wish i knew why it works, but thank you for your "KEEN" eye. Randy Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.