Problem w/ Demo Code...3 drop down list error messages

BeeKeeper
03:25:11
What is needed to fix errors?

Downloaded Demo CODE without any changes. (Demo of Three Multiple drop down list box.)

Results: loaded drop-down list okay, but has two errors messages ??


48 $cat=$_GET['cat']; // This line is added to take care if your global variable is off

56 $cat3=$_GET['cat3']; // This line is added to take care if your global variable is off
__________________________________________________________________________________
Notice: Undefined index: cat in /Users/beekeeper/Sites/dropdown3/dd3/dd3.php on line 48

Notice: Undefined index: cat3 in /Users/beekeeper/Sites/dropdown3/dd3/dd3.php on line 56
opatrick
04-07-2011
I get an error like this:

Notice: Undefined index: cat in C:\wamp\opati\dd3.php on line 33

Notice: Undefined index: cat3 in C:\wamp\opati\dd3.php on line 39
When I select first category from first drop down menu, the first notice disappears, leaving only the second one,which also disappears as I select from second drop down menu. How can this be fixed?

BeeKeeper
04-08-2011
opatrick,
I hope someone will answer your question, because I have the same problem.
dolphinlws2
04-10-2011
Hi all, try this:
@$cat=$_GET['cat'];

@$cat3=$_GET['cat3'];

I have solved the problem.
BeeKeeper
04-13-2011
Thanks
dolphinlws2
04-15-2011
Hi all,

Any idea to change the display the result (as below)
cat=1
subcat=2
subcat3= banana hot

to
cat=Fruit
subcat=Banana

I got no idea to change the code...
BeeKeeper
04-15-2011
dolphinlws2, Get Fruit from table like before, but this time use the cat_id number to get the name of the Fruit...I changed the name of the Fruit to catname because category was also the name of the table and with the table name and the fruit name being the same was confusing, so category is catname in my code. You need to add the HTML STUFF to make the receiving form execute. This works for me.

<?php
require "config.php"; // Your Database details
?>

HTML STUFF


$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$subcat3=$_POST['subcat3'];

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT catname,cat_id FROM category order by catname");
///////////// End of query for first list box////////////

while($row = mysql_fetch_array($quer2))
{
if ($row['cat_id']==$cat)
$fruit = $row['catname'];
}

echo "cat=$cat <br> subcat=$subcat <br> subcat3= $subcat3 <br> fruit=$fruit";

?>

</body>

</html>
Platespin
04-19-2011
Has anybody got any ideas about being able to use non numeric values in the first two dropdown boxes. I can get it to work with numbers in the first two fields but with just text it fails?
dolphinlws2
04-20-2011
Yaya...i also having the same problem.

Below is my code, i have modify as second column is base on first column select(non numeric):

<script type="text/javascript">
function reload(form)
{

var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='index2.php?cat=' + val;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;

self.location='index2.php?cat=' + val + '&cat3=' + val2 ;
}

</script>
<form id="search" method="post" action="indexresult2.php">
<p>
<center>
<?php

// Getting the data from Mysql table for first list box//
$quer2=mysql_query("SELECT DISTINCT manufacturer FROM upload order by manufacturer");
///////////// End of query for first list box////////////

// for second drop down list we will check if category is selected else we will display all the carsubcategory//
@$cat=$_GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT model FROM upload WHERE manufacturer=$cat order by model");
}else{$quer=mysql_query("SELECT DISTINCT model FROM upload order by model"); }
// end of query for second carsubcategory drop down list box //


// for Third drop down list we will check if sub category is selected else we will display all the carsubcategory2///
@$cat3=$_GET['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT location FROM upload WHERE manufacturer=$cat && model=$cat3 order by location");
}else{$quer3=mysql_query("SELECT DISTINCT location FROM upload order by location"); }
// end of query for third carsubcategory2 drop down list box //


echo "<form method=post name=f1 action='indexresult2.php'>";
// Starting of first drop downlist //
echo "<td><select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option></td>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['manufacturer']==$cat){echo "<option selected value='$noticia2[manufacturer]'>$noticia2[manufacturer]</option>"."<BR>";}
else{echo "<option value='$noticia2[manufacturer]'>$noticia2[manufacturer]</option>";}
}
echo "</select>";
// This will end the first drop down list //

// Starting of second drop downlist //
echo "<td><select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option></td>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['model']==$cat3){echo "<option selected value='$noticia[model]'>$noticia[model]</option>"."<BR>";}
else{echo "<option value='$noticia[model]'>$noticia[model]</option>";}
}
echo "</select>";
// This will end the second drop down list //


// Starting of third drop downlist //
echo "<td><select name='subcat3' ><option value=''>Select one</option></td>";
while($noticia = mysql_fetch_array($quer3)) {
echo "<option value='$noticia[location]'>$noticia[location]</option>";
}
echo "</select>";
// This will end the third drop down list //


echo "<td><input type=submit value='Submit'></form></td>";

?>
</center>
</P>
</form>

My database:
(first column)Manufacturer (TEXT)
(second column) Model (TEXT)
(Third column) Location (TEXT)

***Problem is when i select 1st column, nothing in 2nd column after refresh.
If i replace my database ad below:
(first column)Manufacturer (numeric)then it will show 2nd column data after refresh.
Pls HELP!!!
BeeKeeper
04-20-2011
All,
You need an additional step to use text.

You must first use numeric as taught in the demo you downloaded,

THEN do a lookup for the the text in the same row as the numeric "cat_id" to find the corresponding text.

The original demo code is only good for numeric.

Read my previous post for the lookup code.

<?php
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$subcat3=$_POST['subcat3'];

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT catname,cat_id FROM category order by catname");
///////////// End of query for first list box////////////

while($row = mysql_fetch_array($quer2))
{
if ($row['cat_id']==$cat)
$fruit = $row['catname'];
}

echo "cat=$cat <br> subcat=$subcat <br> subcat3= $subcat3 <br> fruit=$fruit";

?>
jwheeler
05-12-2011
Does anyone have an AJAX script to submit the form result into a div on the same page?
dolphinlws2
04-21-2011
I have solved my problem: (below code with correction on '$cat' and '$cat3'

// for second drop down list we will check if category is selected else we will display all the carsubcategory//
@$cat=$_GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT model FROM upload WHERE manufacturer='$cat' order by model");
}else{$quer=mysql_query("SELECT DISTINCT model FROM upload order by model"); }
// end of query for second carsubcategory drop down list box //


// for Third drop down list we will check if sub category is selected else we will display all the carsubcategory2///
@$cat3=$_GET['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT location FROM upload WHERE manufacturer='$cat' && model='$cat3' order by location");
}else{$quer3=mysql_query("SELECT DISTINCT location FROM upload order by location"); }
// end of query for third carsubcategory2 drop down list box //
BeeKeeper
04-22-2011
Thanks I'll give it a try !
jwheeler
04-27-2011
Has anyone tried or does anyone know how to adjust the script so the page doesn't have to reload the each time a selection is made?

smo1234
04-29-2011
By using PHP & Ajax we can avoid reloading of page.
jwheeler
05-12-2011
Thanks for responding, but I have not been able translate that script to a script for three drop downs.

Any suggestions for where I can get help?
Please Login to post your reply or start a new topic