-2

I was developing one simple PHP script in window machine and was testing in xampp. I have completed it and its working fine in my windows machine. Now I have tried to move it in my centos 7 machine which also have xampp. Its giving me error like below

Notice: Undefined index: action in /opt/lampp/htdocs/contacts.php on line 6

My code for that function is like below

if($_GET['action']=="change_status" && $_GET['contact_id']>0 )

    {
        $upd_qry = "update contacts set status = ? where id=?";
        $stmt = mysqli_prepare($mysqli, $upd_qry);
        mysqli_stmt_bind_param($stmt, "ii", $_GET['status'],$_GET['contact_id']);
        $result = mysqli_stmt_execute($stmt);
        $_SESSION['msg']="11";
        header( "Location:contacts.php");
        exit;

    }

I have marked that similar errors in 1-2 more files too. I do not understanding why this happening. I have php 7.2 in my windows machine and in centos its 7.0 let me know if someone know what is wrong with it. Thanks

Mira
  • 75
  • 1
  • 8

1 Answers1

0

The problem is that $_GET['action'] does not exist, when you don't add it in the URL. You can work it around by adding a isset-check

if(isset($_GET['action']) && $_GET['action']=="change_status" && $_GET['contact_id']>0 )

    {
        $upd_qry = "update contacts set status = ? where id=?";
        $stmt = mysqli_prepare($mysqli, $upd_qry);
        mysqli_stmt_bind_param($stmt, "ii", $_GET['status'],$_GET['contact_id']);
        $result = mysqli_stmt_execute($stmt);
        $_SESSION['msg']="11";
        header( "Location:contacts.php");
        exit;

    }
Koen Hollander
  • 1,687
  • 6
  • 27
  • 42