-3

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

if(isset($_POST['bul']))
{
    $marka1=$_POST['marka'];
    $model1=$_POST['model'];

   $que="SELECT * from  otomobil_tablosu WHERE markasi='$marka1' AND modeli='$model1'";
   $res=mysql_query($que);

  while($row = mysql_fetch_row($res)){

  echo "<tr>";
  echo "<td>" . $row['otomobilID'] . "</td>";
  echo "</tr>";

  }

when I want to print the row of table there is undefined index warning... I could not find the problem

Community
  • 1
  • 1
Yilmaz Paçariz
  • 186
  • 1
  • 4
  • 18
  • `$_POST['marka']` and `$_POST['model']`, also `$row['otomobilID']` – Alvin Wong Dec 09 '12 at 11:29
  • 2
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained and the [deprecation process](http://j.mp/Rj2iVR) has begun on it. See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Madara's Ghost Dec 09 '12 at 11:30
  • 1
    In which line of code do you get this warning? – Justin John Dec 09 '12 at 11:30

1 Answers1

3

The specific problem is that mysql_fetch_row() returns an indexed array and not an associative. You want mysql_fetch_assoc().

The more general problem is that you're using mysql_*() functions, and are highly vulnerable to SQL injection. Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308