Home > OS >  undefined index error when use $SESSION in SQL query
undefined index error when use $SESSION in SQL query

Time:11-26

I have a session variable. When I try to use it in a query I get an error.

This is the PHP code:

$_SESSION['nima'] = 'xxxx';
$query = "SELECT * FROM realizacia WHERE connector != '$_SESSION[nima]'

This is the error:

Notice: Undefined index: nima in C:\xampp\htdocs\contohcrud\fetch.php on line 9

Here is a query I use. It returns data which has Unicode characters, but I can not assign it to my table. What can I do?

{
  "draw": 1,
  "recordsTotal": 8,
  "recordsFiltered": 1,
  "data": [
    [
      "3", 
      "\u10d3\u10d0\u10d6\u10d2\u10d8\u10e1 \u10dc\u10d0\u10ec\u10d8\u10da\u10d8 Pring-loaded latch button (85190995)", "7227", 
      "\u10e4\u10d8\u10d6\u10d8\u10d9\u10e3\u10e0\u10d8 \u10de\u10d8\u10e0\u10d4\u10d1\u10d8", 
      "2020-08-01", 
      "RADION \u10e1\u10d0\u10e5\u10dd\u10dc\u10da\u10d8\u10e1 \u10d2\u10d0\u10e7\u10d8\u10d3\u10d5\u10d0", 
      "40.00", 
      "GEL", 
      "40.00"
    ]
  ]
}

CodePudding user response:

Use quotation marks around your session index.

use

$_SESSION['nima'] 

instead of

$_SESSION[nima]

CodePudding user response:

You have a typo in your code

Use code:

$_SESSION['nima'] = 'xxxx';
$query = "SELECT * FROM `realizacia` WHERE `connector` != '{$_SESSION['nima']}'";
  • Related