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











up vote
0
down vote

favorite













This question already has an answer here:




  • Illegal string offset Warning PHP

    12 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







New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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 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 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 at 6:38












  • Based on that output, I think that I'm getting an empty array, am I right?
    – Alan Maldonado
    Nov 17 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 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 at 6:43















up vote
0
down vote

favorite













This question already has an answer here:




  • Illegal string offset Warning PHP

    12 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







New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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 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 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 at 6:38












  • Based on that output, I think that I'm getting an empty array, am I right?
    – Alan Maldonado
    Nov 17 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 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 at 6:43













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • Illegal string offset Warning PHP

    12 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







New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












This question already has an answer here:




  • Illegal string offset Warning PHP

    12 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

    12 answers








php string pdo






share|improve this question







New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 6:28









Alan Maldonado

197




197




New contributor




Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Alan Maldonado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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 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 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 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 at 6:38












  • Based on that output, I think that I'm getting an empty array, am I right?
    – Alan Maldonado
    Nov 17 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 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 at 6:43


















  • Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).
    – Davіd
    Nov 17 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 at 6:38












  • Based on that output, I think that I'm getting an empty array, am I right?
    – Alan Maldonado
    Nov 17 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 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 at 6:43
















Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).
– Davіd
Nov 17 at 6:35




Can you return what var_dump($row); outputs? (Put it above the $row["admin_db"] line).
– Davіd
Nov 17 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 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 at 6:38














Based on that output, I think that I'm getting an empty array, am I right?
– Alan Maldonado
Nov 17 at 6:39




Based on that output, I think that I'm getting an empty array, am I right?
– Alan Maldonado
Nov 17 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 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 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 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 at 6:43












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










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 at 6:49


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










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 at 6:49















up vote
1
down vote



accepted










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 at 6:49













up vote
1
down vote



accepted







up vote
1
down vote



accepted






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 at 7:02

























answered Nov 17 at 6:45









George Mylonas

312




312












  • This worked! But I still don't know why tho, can you explaing why this worked?
    – Alan Maldonado
    Nov 17 at 6:49


















  • This worked! But I still don't know why tho, can you explaing why this worked?
    – Alan Maldonado
    Nov 17 at 6:49
















This worked! But I still don't know why tho, can you explaing why this worked?
– Alan Maldonado
Nov 17 at 6:49




This worked! But I still don't know why tho, can you explaing why this worked?
– Alan Maldonado
Nov 17 at 6:49



Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?