0

I have been surfing for a solution to this problem for awhile now and most of what I find is that people who aren't checking to see the the $_GET variable is set are the ones having this error. However, I do check if they are set yet I still come up with this error. Here is my code:

$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";

And the error is:

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"}]
Alex Hamilton
  • 77
  • 4
  • 9

1 Answers1

3

You need to check when you're first attempting to use the variables.

i.e.:

$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) { 
    ...

I suspect you also urgently need to read How can I prevent SQL injection in PHP?, but this is a guess as I can't see how you're executing your SQL queries.

Community
  • 1
  • 1
John Parker
  • 54,048
  • 11
  • 129
  • 129