Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
There is an error in my code but the code works perfectly. I mean all the values are inserted in the database but there is an error like this on the screen:
Severity: Notice
Message: Array to string conversion
Filename: models/some_model.php
Line Number: 106
This is my code:
View:
<?php foreach($app as $row){
echo "<tr><td><input type=checkbox name=appname[] value='".$row->app_name."'/>".$row->id."</td><td>".$row->app_name."</td><tr>".
?>
Controller:
public function hide(){
$this->load->model('some_model');
$visi = $this->input->post('appname');
$success = $this->some_model->hideApp($visi);
foreach($visi as $key=>$value)
{
$success = $this->some_model->hideApp($visi[$key]);
}
if($success == TRUE)
$this->hideApp_page(TRUE);
else $this->hideApp_page(FALSE);
}
Model:
public function hideApp($visi){
$visi = $this->db->escape_str($visi);
$queryStr = "UPDATE appwarehouse.application_table SET visibility='hidden' where app_name='$visi';"; /* this is line 106*/
$query = $this->db->query($queryStr);
return $query;
}
$visi is array like [1,2,3,4]
when you put $visi in hideApp()
it will be display "array to string error"
so maybe you can remove this line $success = $this->some_model->hideApp($visi);
you have already do some_model->hideApp($visi[$key]) in the foreach loop
so i don't know why you write this$success = $this->some_model->hideApp($visi);
if you still want to run $success = $this->some_model->hideApp($visi);
you have to put $visi into a string
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a PDO PHP file making use of just one $_POST value stored on the $data array, and if an statement is true, a second value is added to that array to make a new query with two values:
<?php
session_start();
include("../conexionbbdd.php");
if($_SESSION['estado'] == 'activo' && $_SESSION['rol'] == '1'){
$data = array(
'us_id' => $_POST['us_id'],
);
$selectUsers= "SELECT * FROM ws_users WHERE us_id= :us_id";
$statementSelectUsers = $pdo->prepare($selectUsers);
$statementSelectUsers->execute($data);
$result = $statementSelectUsers->fetch(PDO::FETCH_ASSOC);
$us_fk_ui_id = $result['us_fk_ui_id'];
if($us_fk_ui_id==='1'){
$data['us_credits']=$_POST['us_credits'];
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
$statementUpdateUser = $pdo->prepare($updateUser);
$statementUpdateUser->execute($data);
}
Everything goes fine untill the $statementUpdateUser->execute($data); line (34), where I get the usual error
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1065
Query was empty in C:\wamp\www**********\actions\ad_updateUserInfo.php on
line 34
As far as I've seen, this should be due to the unexistance of one of the placeholders on the array, but if I print the array values after the $data['us_credits']=$_POST['us_credits']; it seems to be correct, having the 2 expected values needed for my query:
Array (
[0] => 2
[1] => 1.5 )
How could I check where the mistake is? There's no possibility of echoing the query as it is an object unable to transform on string.
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
^^^ WTF??
You have to pay more attention to the code you write. Stack Overflow is NOT the service for finding typos for you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am getting an error while running this code:
Fatal error: Call to a member function bindParam() on boolean in D:\xampp\htdocs\ipack\insertstatus.php on line 9
<?php
header('Access-Control-Allow-Origin: *');
include 'dbconnection.php';
$jobno = "AFE/0001/2015";
$jobseq = 0;
//to get INTJOBNO
$intjobno = "";
$data = $dbh->query("select INTJOBNO from PRTJOBHD where JOBNO = :jobno and JOBSEQ = :jobseq");
$data->bindParam(':jobno',$jobno,PDO::PARAM_STR);
$data->bindParam(':jobseq',$jobseq,PDO::PARAM_STR);
$data->execute();
foreach($data as $row) {
$intjobno = $row['INTJOBNO'];
echo $intjobno;
}
>
Have a look at this answer: PDO's query vs execute. You cannot bind parameters to PDO query, you need to use prepare instead.
header('Access-Control-Allow-Origin: *');
include 'dbconnection.php';
$jobno = "AFE/0001/2015";
$jobseq = 0;
//to get INTJOBNO
$intjobno = "";
$data = $dbh->prepare("select INTJOBNO from PRTJOBHD where JOBNO = :jobno and JOBSEQ = :jobseq");
$data->bindParam(':jobno',$jobno,PDO::PARAM_STR);
$data->bindParam(':jobseq',$jobseq,PDO::PARAM_STR);
$data->execute();
foreach($data as $row) {
$intjobno = $row['INTJOBNO'];
echo $intjobno;
}
PDO::query() returns a PDOStatement object, or FALSE on failure.
Source
It means your query has failed for some reason.
In this case you are using the wrong function to do what you want to do.
You need to prepare your statement since you want to bind two parameters in your query.
Use $dbh->prepare() instead of $dbh->query().
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The following code is not working properly:
$query = $this->db->query("SELECT accountType FROM users WHERE id = $loggedID" );
It errors if the $loggedID is words like "justin", but if its only number like 201110523, it works. I don't know what is wrong. The datatype of the id in users is varchar.
public function account_type_student(){
$loggedID = $this->input->post('id');
$query = $this->db->query("SELECT accountType FROM users WHERE id = $loggedID" );
foreach ($query->result() as $row)
{
$query = $row->accountType;
}
if($query=="student"){
return true;
}
else{
return false;
}
}
When it is a word / string like "justin" then you have to escape your variable:
$query = $this->db->query("SELECT accountType FROM users WHERE id = '$loggedID' " );
Or use the active pattern syntax:
$this->db->select('accountType');
$this->db->where('id', $loggedID);
$query = $this->db->get('users');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I' am running into a problem where an array is not being able to shuffle. I want the array to randomized for each page loads. I followed the documentation but something still wrong over here
Error Message
Warning: Invalid argument supplied for foreach() in E:\xampp\htdocs\projects\snppets\sidebar.php on line 65
This is the code that gets the friends list, makes the sting into array, counts the array and shuffles it.
$friends = get_friends_IDS($profile_id);
$friends = make_string_to_ARRAY($friends);
$friends_count = count($friends);
$friends = shuffle($friends);
This is the code that is in line 65
<?php
foreach($friends as $id){
$sql = "SELECT profile_id, profile_photo, profile_username, profile_name FROM profile WHERE profile_id='$id' LIMIT 1";
$query = $db->SELECT($sql);
$rows = $db->FETCH_OBJECT();
if($db->NUM_ROWS() > 0){
foreach($rows as $row){
$friends_profile_id = $row->profile_id;
$friends_profile_photo = $row->profile_photo;
$friends_profile_username = $row->profile_username;
$friends_profile_name = $row->profile_name;
}
}
}
?>
This function gets the friends list from the database
function get_friends_IDS($profile_id){
global $db;
$sql = "SELECT profile_id, profile_friends FROM profile WHERE profile_id='$profile_id' LIMIT 1";
$query = $db->SELECT($sql);
if($db->NUM_ROWS()){
foreach($db->FETCH_OBJECT() as $row){
return $row->profile_friends;
}
}
}
This is the function makes a string into array
function make_string_to_ARRAY($array){
$array = explode(',', $array);
return $array;
}
When I remove the shuffle then it works fine...
shuffle() returns boolean value.
So $friends = shuffle($friends); makes $friends as a boolean variable.
just use shuffle($friends); to shuffle it
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
I want to fetch every result from table 'Themes'.
function display_all_themes()
{
global $pdo;
$select = $pdo->prepare("SELECT * FROM themes");
$select->execute();
while ($row = $select->fetch(PDO::FETCH_ASSOC))
{
echo $select['theme_name'].'<br />';
}
}
Getting this error:
Fatal error: Cannot use object of type PDOStatement as array in C:\xampp\htdocs\driptone\inc\functions.inc.php on line 137
Line 137:
echo $select['theme_name'].'<br />';
What is the problem?
Thanks.
You're using $select instead of $row inside loop.
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
echo $row['theme_name'].'<br />';
}
use $row, except $select
echo $row['theme_name'].'<br />';
You assigned it to $row but you're calling $select.
Should be:
while ($row = $select->fetch(PDO::FETCH_ASSOC))
{
echo $row['theme_name'].'<br />';
}