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!
php string pdo
New contributor
marked as duplicate by Nick, Nigel Ren
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.
add a comment |
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!
php string pdo
New contributor
marked as duplicate by Nick, Nigel Ren
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 whatvar_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
add a comment |
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!
php string pdo
New contributor
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
php string pdo
New contributor
New contributor
New contributor
asked Nov 17 at 6:28
Alan Maldonado
197
197
New contributor
New contributor
marked as duplicate by Nick, Nigel Ren
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
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 whatvar_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
add a comment |
Can you return whatvar_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
add a comment |
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
This worked! But I still don't know why tho, can you explaing why this worked?
– Alan Maldonado
Nov 17 at 6:49
add a comment |
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
This worked! But I still don't know why tho, can you explaing why this worked?
– Alan Maldonado
Nov 17 at 6:49
add a comment |
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
This worked! But I still don't know why tho, can you explaing why this worked?
– Alan Maldonado
Nov 17 at 6:49
add a comment |
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
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
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
add a comment |
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
add a comment |
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