B
B
Baffer2019-02-13 16:24:14
PHP
Baffer, 2019-02-13 16:24:14

How to fix Notice: Undefined index: uid in?

Error when calling uinfo function Error itself: Notice : Undefined index: uid in .... Function itself:
<?php if(uinfo($_SESSION['uid'],"who") == 2) {?>

function uinfo($uid,$value) {
  global $con;
  $sql = $con->prepare("SELECT * FROM users WHERE username =?");
        $sql->execute(array($uid));
  $row = $sql->fetch(PDO::FETCH_ASSOC);
  return $row[$value];
}

The fact is that the error disappears during authorization. there is a session. But the error appears if the user is not authorized.
isset throws another error annot use isset() on the result of an expression (you can use "null !== expression" instead)
How can I fix this error?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2019-02-13
@roman94

$_SESSION['uid'] !== null

A
Alexander Aksentiev, 2019-02-13
@Sanasol

php.net/manual/ru/function.empty.php
php.net/manual/ru/function.isset.php
php.net/manual/ru/function.array-key-exists.php

M
Mikhail Krutikov, 2019-02-13
@Sunsetboy

for example, in the function check
if(!is_null($uid)) {
.. database query
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question