[英]undefined index notice: Why is this happening and how do I fix it?
我的php代码有问题,这使我发疯。 我在这行上得到未定义的索引通知: echo " <input type=\\"text\\" name=\\"column3\\" value=\\"".$row['hca']."\\"/>\\n";
。 似乎是随机发生的错误。 让我困惑的是,用于显示数据的表单代码与上一行和后一行完全相同,但是此代码段出现了错误/通知。 最重要的是,即使我已经在后端查询了数据库并发现数据确实存在,也没有像应该那样从数据库显示数据。 为什么会发生这种情况,我该怎么解决? 我的代码如下:
if ($count !== 0) {
while($row = mysql_fetch_array($result)) {
echo "<div class=\"addform\"><form method='get' action=\"update.php\">\n";
echo " <input type=\"text\" value=\"".$row['tfid']."\" name=\"column1\">\n";
echo " <input type=\"text\" name=\"column2\" value=\"".$row['fname']."\"/>\n";
echo " <input type=\"text\" name=\"column3\" value=\"".$row['lname']."\"/>\n";
echo " <input type=\"text\" name=\"column3\" value=\"".$row['hha']."\"/>\n"; //there are issues here.
echo " <input type=\"text\" name=\"column5\" value=\"".$row['file']."\"/>\n";
echo " <input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n";
echo "<a href=\"delete.php?column1=".$row['tfid']."\"><img title='Delete Row' alt=\"Delete\" class='del' src='images/delete.png'/></a></form></div>\n";
}
echo "</table><br />\n";
} else {
echo "<b><center>NO DATA</center></b>\n";
}
人们可以提供的任何提示都会有所帮助。
谢谢,约翰
检查数据库,并确保字段名称与数组的索引( $row
)相匹配。
您的表应具有所有这些字段: tfid
, fname
, lname
, hha
, file
和tfid
另外,转义和PHP / echo / HMTL可能会导致视觉噪音,也许这会使您的代码更易于调试:
<?php if ($count !== 0) : ?>
<?php while($row = mysql_fetch_array($result)): ?>
<div class="addform">
<form method="get" action="update.php">
<input type="text" value="<?php echo $row['tfid'] ?>" name="column1">
<input type="text" name="column2" value="<?php echo $row['fname'] ?>"/>
<input type="text" name="column3" value="<?php echo $row['lname'] ?>"/>
<input type="text" name="column3" value="<?php echo $row['hha'] ?>"/>
<input type="text" name="column5" value="<?php echo $row['file'] ?>"/>
<input type="image" src="images/update.png" alt="Update Row" class="update" title="Update Row">;
<a href="delete.php?column1=<?php echo $row['tfid'] ?>">
<img title="Delete Row" alt="Delete" class="del" src="images/delete.png"/>
</a>
</form>
</div>
<?php endwhile ?>
<?php else: ?>
<b><center>NO DATA</center></b>
<?php endif ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.