0

I want a drop-box to show values of my database but can't get it to work.I'm getting

Notice: Undefined index:.... Call Stack #TimeMemoryFunctionLocation

Here is the dropbox code:

Fabrikat:     <br />    <select name="tillverkare_search" id="tillverkare_search">
                        <option value="" selected="selected">Välj</option>
                        <?php do {  ?>
                        <option value="<?php echo $row_Fabrikat['Tillverkare']?>" <?php if (!(strcmp($row_Fabrikat['Tillverkare'], $row_Fabrikat['Tillverkare']))) ?>><?php echo $row_Fabrikat['Tillverkare']?></option>
                        <?php
                        } while ($row_Fabrikat = mysql_fetch_assoc($Fabrikat)); ?>
                        </select><br />

And here I defined it with recordset made in Dreamweaver:

mysql_select_db($database_Audiologiska, $Audiologiska);
$query_Fabrikat = "SELECT tillverkare FROM vanster_implantat";
$Fabrikat = mysql_query($query_Fabrikat, $Audiologiska) or die(mysql_error());
$row_Fabrikat = mysql_fetch_assoc($Fabrikat);
$totalRows_Fabrikat = mysql_num_rows($Fabrikat);

The SQL queries works correctly in phpMyAdmin so there is no problem with the SQL query.

My other drop-boxes that has the same function works fine, but I don't know why this one wont work.

halfer
  • 19,824
  • 17
  • 99
  • 186
david
  • 5
  • 1
  • 4
  • `SELECT tillverkare` / `$row_Fabrikat['Tillverkare']`. Those are different -> `tillverkare` != `Tillverkare`. You need to do same case, ie. `$row_Fabrikat['tillverkare']` – Sean Aug 04 '14 at 19:34
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Sean Aug 04 '14 at 19:35

2 Answers2

0

Your query is using a lower case column name:

$query_Fabrikat = "SELECT tillverkare FROM vanster_implantat";

But in your options you use 'Tillverkare' instead.

<option value="<?php echo $row_Fabrikat['Tillverkare']?>" <?php if (!(strcmp($row_Fabrikat['Tillverkare'], $row_Fabrikat['Tillverkare']))) ?>><?php echo $row_Fabrikat['Tillverkare']?></option>

Solution:

Change it to lowercase too:

<option value="<?php echo $row_Fabrikat['tillverkare']?>" <?php if (!(strcmp($row_Fabrikat['tillverkare'], $row_Fabrikat['tillverkare']))) ?>><?php echo $row_Fabrikat['tillverkare']?></option>
VMai
  • 10,156
  • 9
  • 25
  • 34
0

Not relevant, but this might help someone.

The error can also be caused by incomplete query (part of it is missing e.g $variable is empty) or by using & instead of && for AND operation. Although & might work perfectly fine in some case and not give any error at all.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136