【发布时间】:2013-04-07 22:51:18
【问题描述】:
为什么在我添加排序功能时我的代码中出现未定义的索引错误?这些是我遇到的错误
注意:未定义索引:在第 58 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义的索引:在第 61 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义的索引:在第 64 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义的索引:在第 67 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义的索引:在第 70 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义的索引:在第 73 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
注意:未定义索引:在第 76 行的 C:\xampp\htdocs\how are things\admin panel\view.php 中排序
这是第 58 61 64 67 70 73 76 行的代码
$result = "SELECT * FROM customers";
if($_GET['sort'] == 'first_name'){
$result .= " ORDER BY first_name";
}
else if($_GET['sort'] == 'last_name'){
$result .= " ORDER BY last_name";
}
else if($_GET['sort'] == 'address'){
$result .= " ORDER BY address";
}
else if($_GET['sort'] == 'phone_number'){
$result .= " ORDER BY phone_number";
}
else if($_GET['sort'] == 'email'){
$result .= " ORDER BY email";
}
else if($_GET['sort'] == 'city'){
$result .= " ORDER BY city";
}
else if($_GET['sort'] == 'country'){
$result .= " ORDER BY country";
}
$result = mysql_query($result) or die(mysql_error());
【问题讨论】:
-
欢迎来到 Stack Overflow!请不要使用
mysql_*函数编写新代码。它们不再维护,社区已经开始deprecation process。看到red box?相反,您应该了解prepared statements 并使用PDO 或MySQLi。如果你选择 PDO here is a good tutorial. -
使用
if(isset($_GET['sort']) && $_GET['sort']== 'someval') -
我只是好奇——很多人似乎都在问这个问题——但是,你对
Undefined index: sort有什么不明白的地方?你使用$_GET['sort']...你收到通知说它是未定义的......而且......什么都没有?