php中未定义的索引警告

时间:2012-12-09 11:27:31

标签: php

  

可能重复:
  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>";

  }

当我想打印表格行时,有未定义的索引警告......我找不到问题

1 个答案:

答案 0 :(得分:3)

具体问题是mysql_fetch_row()会返回索引数组而不是关联数据。你想要mysql_fetch_assoc()

更普遍的问题是您正在使用mysql_*()函数,并且非常容易受到SQL注入的攻击。 Please, don't use mysql_* functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDOMySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial