Q [PHP]: What does this mean? -> Warning: Illegal string offset [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • Illegal string offset Warning PHP

    13 answers




Recently I had a problem with one of my PHP codes, and made this thread
and I got a solution on that, but when applying that solution, another error came up!



Warning: Illegal string offset 'admin_db' in C:wamp64wwwNewKaliincludesuser.inc.php on line 55


This error is complaining about this section of my code:



public function isAdmin($user){
$userToGet = $user;

$stmt = $this->Connect()->prepare("SELECT admin_db FROM user_secure WHERE username_db=?");
$query1 = $stmt->execute([$userToGet]);

if(!$query1)
{
die("Execute query error, because: ". print_r($this->Connect()->errorInfo(),true) );
}else{
foreach ( $stmt->fetch() as $row) {
$value = $row["admin_db"];
if($value == 1){
return true;
} else {
return false;
}
}
}
}


It happens here:




$value = $row["admin_db"];




Even when this error happens, the function is still returning a boolean value, which I require in another code.



I'm still new to PHP, and I don't know what this error means, or what am I doing wrong...



Thank you for your time!










share|improve this question













marked as duplicate by Nick, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 7:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

    – Davіd
    Nov 17 '18 at 6:35











  • This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

    – Alan Maldonado
    Nov 17 '18 at 6:38













  • Based on that output, I think that I'm getting an empty array, am I right?

    – Alan Maldonado
    Nov 17 '18 at 6:39











  • I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

    – Davіd
    Nov 17 '18 at 6:41











  • Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

    – Alan Maldonado
    Nov 17 '18 at 6:43


















0
















This question already has an answer here:




  • Illegal string offset Warning PHP

    13 answers




Recently I had a problem with one of my PHP codes, and made this thread
and I got a solution on that, but when applying that solution, another error came up!



Warning: Illegal string offset 'admin_db' in C:wamp64wwwNewKaliincludesuser.inc.php on line 55


This error is complaining about this section of my code:



public function isAdmin($user){
$userToGet = $user;

$stmt = $this->Connect()->prepare("SELECT admin_db FROM user_secure WHERE username_db=?");
$query1 = $stmt->execute([$userToGet]);

if(!$query1)
{
die("Execute query error, because: ". print_r($this->Connect()->errorInfo(),true) );
}else{
foreach ( $stmt->fetch() as $row) {
$value = $row["admin_db"];
if($value == 1){
return true;
} else {
return false;
}
}
}
}


It happens here:




$value = $row["admin_db"];




Even when this error happens, the function is still returning a boolean value, which I require in another code.



I'm still new to PHP, and I don't know what this error means, or what am I doing wrong...



Thank you for your time!










share|improve this question













marked as duplicate by Nick, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 7:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

    – Davіd
    Nov 17 '18 at 6:35











  • This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

    – Alan Maldonado
    Nov 17 '18 at 6:38













  • Based on that output, I think that I'm getting an empty array, am I right?

    – Alan Maldonado
    Nov 17 '18 at 6:39











  • I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

    – Davіd
    Nov 17 '18 at 6:41











  • Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

    – Alan Maldonado
    Nov 17 '18 at 6:43














0












0








0









This question already has an answer here:




  • Illegal string offset Warning PHP

    13 answers




Recently I had a problem with one of my PHP codes, and made this thread
and I got a solution on that, but when applying that solution, another error came up!



Warning: Illegal string offset 'admin_db' in C:wamp64wwwNewKaliincludesuser.inc.php on line 55


This error is complaining about this section of my code:



public function isAdmin($user){
$userToGet = $user;

$stmt = $this->Connect()->prepare("SELECT admin_db FROM user_secure WHERE username_db=?");
$query1 = $stmt->execute([$userToGet]);

if(!$query1)
{
die("Execute query error, because: ". print_r($this->Connect()->errorInfo(),true) );
}else{
foreach ( $stmt->fetch() as $row) {
$value = $row["admin_db"];
if($value == 1){
return true;
} else {
return false;
}
}
}
}


It happens here:




$value = $row["admin_db"];




Even when this error happens, the function is still returning a boolean value, which I require in another code.



I'm still new to PHP, and I don't know what this error means, or what am I doing wrong...



Thank you for your time!










share|improve this question















This question already has an answer here:




  • Illegal string offset Warning PHP

    13 answers




Recently I had a problem with one of my PHP codes, and made this thread
and I got a solution on that, but when applying that solution, another error came up!



Warning: Illegal string offset 'admin_db' in C:wamp64wwwNewKaliincludesuser.inc.php on line 55


This error is complaining about this section of my code:



public function isAdmin($user){
$userToGet = $user;

$stmt = $this->Connect()->prepare("SELECT admin_db FROM user_secure WHERE username_db=?");
$query1 = $stmt->execute([$userToGet]);

if(!$query1)
{
die("Execute query error, because: ". print_r($this->Connect()->errorInfo(),true) );
}else{
foreach ( $stmt->fetch() as $row) {
$value = $row["admin_db"];
if($value == 1){
return true;
} else {
return false;
}
}
}
}


It happens here:




$value = $row["admin_db"];




Even when this error happens, the function is still returning a boolean value, which I require in another code.



I'm still new to PHP, and I don't know what this error means, or what am I doing wrong...



Thank you for your time!





This question already has an answer here:




  • Illegal string offset Warning PHP

    13 answers








php string pdo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 '18 at 6:28









Alan MaldonadoAlan Maldonado

158




158




marked as duplicate by Nick, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 7:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Nick, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 7:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

    – Davіd
    Nov 17 '18 at 6:35











  • This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

    – Alan Maldonado
    Nov 17 '18 at 6:38













  • Based on that output, I think that I'm getting an empty array, am I right?

    – Alan Maldonado
    Nov 17 '18 at 6:39











  • I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

    – Davіd
    Nov 17 '18 at 6:41











  • Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

    – Alan Maldonado
    Nov 17 '18 at 6:43



















  • Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

    – Davіd
    Nov 17 '18 at 6:35











  • This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

    – Alan Maldonado
    Nov 17 '18 at 6:38













  • Based on that output, I think that I'm getting an empty array, am I right?

    – Alan Maldonado
    Nov 17 '18 at 6:39











  • I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

    – Davіd
    Nov 17 '18 at 6:41











  • Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

    – Alan Maldonado
    Nov 17 '18 at 6:43

















Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

– Davіd
Nov 17 '18 at 6:35





Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).

– Davіd
Nov 17 '18 at 6:35













This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

– Alan Maldonado
Nov 17 '18 at 6:38







This is the output when my function is called: C:wamp64wwwNewKaliincludesuser.inc.php:55:string '1' (length=1)

– Alan Maldonado
Nov 17 '18 at 6:38















Based on that output, I think that I'm getting an empty array, am I right?

– Alan Maldonado
Nov 17 '18 at 6:39





Based on that output, I think that I'm getting an empty array, am I right?

– Alan Maldonado
Nov 17 '18 at 6:39













I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

– Davіd
Nov 17 '18 at 6:41





I don't think so, it seems that $row is simply a string of '1', I think you might be using the wrong method somewhere.

– Davіd
Nov 17 '18 at 6:41













Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

– Alan Maldonado
Nov 17 '18 at 6:43





Well if the content of that var is '1', then that's exactly the value that I'm expecting, but I don't understand why it's deploying a warning...

– Alan Maldonado
Nov 17 '18 at 6:43












1 Answer
1






active

oldest

votes


















1














try use PDO::FETCH_ASSOC



fetchAll(PDO::FETCH_ASSOC)


I think your fetch is not returning an array indexed by column names but returns an array indexed by 0-indexed column number.



http://php.net/manual/en/pdostatement.fetch.php






share|improve this answer


























  • This worked! But I still don't know why tho, can you explaing why this worked?

    – Alan Maldonado
    Nov 17 '18 at 6:49


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














try use PDO::FETCH_ASSOC



fetchAll(PDO::FETCH_ASSOC)


I think your fetch is not returning an array indexed by column names but returns an array indexed by 0-indexed column number.



http://php.net/manual/en/pdostatement.fetch.php






share|improve this answer


























  • This worked! But I still don't know why tho, can you explaing why this worked?

    – Alan Maldonado
    Nov 17 '18 at 6:49
















1














try use PDO::FETCH_ASSOC



fetchAll(PDO::FETCH_ASSOC)


I think your fetch is not returning an array indexed by column names but returns an array indexed by 0-indexed column number.



http://php.net/manual/en/pdostatement.fetch.php






share|improve this answer


























  • This worked! But I still don't know why tho, can you explaing why this worked?

    – Alan Maldonado
    Nov 17 '18 at 6:49














1












1








1







try use PDO::FETCH_ASSOC



fetchAll(PDO::FETCH_ASSOC)


I think your fetch is not returning an array indexed by column names but returns an array indexed by 0-indexed column number.



http://php.net/manual/en/pdostatement.fetch.php






share|improve this answer















try use PDO::FETCH_ASSOC



fetchAll(PDO::FETCH_ASSOC)


I think your fetch is not returning an array indexed by column names but returns an array indexed by 0-indexed column number.



http://php.net/manual/en/pdostatement.fetch.php







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 7:02

























answered Nov 17 '18 at 6:45









George MylonasGeorge Mylonas

312




312













  • This worked! But I still don't know why tho, can you explaing why this worked?

    – Alan Maldonado
    Nov 17 '18 at 6:49



















  • This worked! But I still don't know why tho, can you explaing why this worked?

    – Alan Maldonado
    Nov 17 '18 at 6:49

















This worked! But I still don't know why tho, can you explaing why this worked?

– Alan Maldonado
Nov 17 '18 at 6:49





This worked! But I still don't know why tho, can you explaing why this worked?

– Alan Maldonado
Nov 17 '18 at 6:49





Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly