0

一段时间以来,我一直在寻找解决这个问题的方法,我发现的大部分内容是那些没有检查 $_GET 变量是否设置的人是有这个错误的人。但是,我确实检查了它们是否已设置但我仍然想出了这个错误。这是我的代码:

$customer_id = $_GET['customer_id'];
$actual_customer_id = $_GET['actual_customer_id'];


if (isset($_GET['customer_id'])&& $_GET['actual_customer_id'])    
{    
$query = "SELECT rewards_points.points,customers.id AS customerID, customers.email
 FROM rewards_points,customers WHERE rewards_points.customer_id= $customers_id AND
  $actual_customer_id = rewards_points.actual_customer_id";
}


$query = "SELECT rewards_points.points,customers.id AS customerID, customers.email
 FROM rewards_points,customers";

错误是:

Notice: Undefined index: customer_id in /Applications/MAMP/htdocs/insertintotestt.php on line 14

Notice: Undefined index: actual_customer_id in /Applications/MAMP/htdocs/insertintotestt.php on line 15
[{"points":"20","customerID":"1","email":"someEmail@gmail.com 
 {"points":"20","customerID":"2","email":"otherEmail@gmail.com"},
 {"points":"10","customerID":"1","email":"aha238@gmail.com"},
 {"points":"10","customerID":"2","email":"spgiegg@gmail.com"},
 {"points":"15","customerID":"1","email":"aha238@gmail.com"},
 {"points":"15","customerID":"2","email":"spgiegg@gmail.com"},
 {"points":"25","customerID":"1","email":"aha238@gmail"},
 {"points":"25","customerID":"2","email":"spgiegg@gmail.com"}]
4

1 回答 1

3

您需要检查何时首次尝试使用这些变量。

IE:

$customer_id = isset($_GET['customer_id']) ? $_GET['customer_id'] : null;
$actual_customer_id = isset($_GET['actual_customer_id']) ? $_GET['actual_customer_id'] : null;

if ($customer_id && $actual_customer_id) { 
    ...

怀疑您也迫切需要阅读如何防止 PHP 中的 SQL 注入?,但这是一个猜测,因为我看不到您是如何执行 SQL 查询的。

于 2013-08-25T13:50:01.500 回答