Forum Sign UP Login Contact Us
HOME : Forum : SQL and Database : Post New Topic
Problem w/ Demo Code...3 drop down list error messages
BeeKeeper
03:25:11 17:13
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:11 23:19
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:11 10:07
opatrick,
I hope someone will answer your question, because I have the same problem.
dolphinlws2
04:10:11 12:05
Hi all, try this:
@$cat=$_GET['cat'];

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

I have solved the problem.
BeeKeeper
04:13:11 13:22
Thanks
dolphinlws2
04:15:11 11:15
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:11 11:31
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:11 13:10
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:11 09:36
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:11 13:50
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:11 15:21
Does anyone have an AJAX script to submit the form result into a div on the same page?
dolphinlws2
04:21:11 12:23
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:11 09:24
Thanks I'll give it a try !
jwheeler
04:27:11 13:21
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?

subhendu
04:29:11 21:36
By using PHP & Ajax we can avoid reloading of page.
jwheeler
05:12:11 15:22
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
Privacy Policy | Disclaimer
©2000 - 2014 plus2net.com All rights reserved worldwide