SQL Error: 1054: The column 'Array' in CakePHP 1.3 is unrecognized

I am currently using the CakePHP-Photo-Behavior from the repository https://github.com/dilab/CakePHP-Photo-Behavior and I encountered an error while running it.

The error message states: SQL Error: 1054: Unknown column 'Array' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]

This error occurs when trying to execute the following query: INSERT INTO photos (title, description, photo_dir, photo, school_id, user_id, is_slider, modified, created) VALUES ('skjg', 'lkhg', '', Array, 1, 1, 1, '2013-04-12 01:14:09', '2013-04-12 01:14:09')

Here is a snippet of the model:

var $actsAs = array('Photo'=>array(
                    'dir'=>array('upload_directory'),
                    'file_field'=>array('photo'),
                    'file_db_file'=>array('photo'),
                    'thumb'=>array(true),
                    'thumb_size'=>array(array("100x100"))
));

And here is the relevant code from the view:

<?php echo $this->Form->create('Photo', array('type' => 'file')); ?>
<?php echo $this->Form->input('Photo.title'); ?>
<?php echo $this->Form->input('Photo.description', array('type' => 'textarea', 'rows' => 3)); ?>
<?php echo $this->Form->input('Photo.photo', array('type' => 'file')); ?>
<?php echo $this->Form->input('Photo.photo_dir', array('type' => 'hidden')); ?>
<?php echo $this->Form->end(__('Upload', true));?>

Lastly, the relevant code from the controller:

function admin_add_slider() {
    debug($this->params);

    if (!empty($this->data)) {

        //set the school id
        $session_school_id = $this->Session->read('Userinfo.currentSchoolid');
        $session_user_id = $this->Session->read('Userinfo.id');
        $this->data['Photo']['school_id'] = $session_school_id;
        $this->data['Photo']['user_id'] = $session_user_id;
        $this->data['Photo']['is_slider'] = 1;
        $this->Photo->create();
        if ($this->Photo->save($this->data)) {
            $this->Session->setFlash(__('The Photo has been saved', true));
            $this->redirect(array('action' => 'view_slider'));
        } else {
            $this->Session->setFlash(__('The Photo could not be saved. Please, try again.', true));
        }
    }

}

And the debug information:

$this->data] => Array
    (
        [Photo] => Array
            (
                [title] => skjg
                [description] => lkhg
                [photo_dir] => 
                [photo] => Array
                    (
                        [name] => PLDMonth6Student_img_2.jpg
                        [type] => image/jpeg
                        [tmp_name] => C:\xampp\tmp\phpBA8C.tmp
                        [error] => 0
                        [size] => 42085
                    )

            )

    )

Finally, the table structure is as follows:

Table: id, title, description, small, large, is_slider, created, modified, school_id, user_id, photo, photo_dir

Thanks, Robert

Answer №1

I haven't had the opportunity to utilize that particular function, but it is worth considering whether your configuration should resemble the following:

var $actsAs = array('Image'=>array(
    'directory'=>'upload_folder',
    'file_field'=>'image_file',
    'database_field'=>'image_data',
    'thumbnail_enabled'=>true,
    'thumbnail_size'=>array("100x100")
));

Answer №2

Add a new field called "dbColumn" to the configuration array. This field will only take effect if the "allowEmpty" field is set to TRUE. The value of this field should be the same as your database column name, which in my case is "image".

public $actsAs = array( 
'Uploader.Attachment' => array(
    'image' => array(
            'baseDir'       => '',
            'uploadDir'     => 'files/uploads/',
            'overwrite'     => true,
            'stopSave'      => true,
            'allowEmpty'    => true,
            'dbColumn' => 'image'                           
    )
  )
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Received an email with another "toaddress". Where can it be located?

I recently received an email that was sent to multiple addresses on the same server. The server is set up for 'catch all'. However, when I check the header (imap_headerinfo) or overview (imap_fetch_overview), I can only see one 'to address&a ...

What is the best way to create an htaccess file for showing user-friendly URLs?

I have recently created a website and I am trying to set up a user-friendly URL structure. Currently, the URL for my website looks like this: http://example.com/1/post To achieve this, I am passing query strings in the following way: <a href="page.ph ...

Find the most affordable rate in the JSON data without knowledge of the parent label

I am seeking to extract the best deal from JSON data obtained through an API call and decoded using json_decode. The structure is as follows: products productnumber -> price $product_array['products'][..changingnumber..]['value'] ...

Executing multiple loops of MySQL queries using PHP

There are two tables that are crucial for a trivia quiz game at this stage: scores and quiz. I have implemented multiple nested PHP and MySQL loops to achieve the desired results. However, I am seeking a more streamlined approach with potentially fewer dat ...

What is causing the issue in PHP Ajax Laravel is evident, but what about the solution?

In the view, I have implemented an Ajax code that sends the selected index from a Select Box to the Controller. The Controller processes this data and retrieves the correct result from the Model. While debugging in Firebug, I can see that the Controller ha ...

Failing to send contact information using JSON in PHP

I attempted to transmit JSON data to PHP for email processing, but encountered an issue where the process veered into the 'else' condition during debugging. Here is the code snippet: HTML <form id="cbp-mc-form" class="cbp-mc-form" method="po ...

Can the default parameter values for routes be dynamically updated in Symfony2?

I am working on a Symfony2 controller where I have defined a route using annotations. For example: @Route("/{year}", name="show_list_for_user", defaults={ "year" = "2012" }) I am wondering if it is feasible to make the default year dynamic. Perhaps by re ...

Using Laravel to connect custom fonts

After previously discussing and experimenting with linking custom font files in Laravel, I encountered an issue where the fonts were not displaying correctly on my website. Due to Laravel's router, directly linking to font files in CSS was posing a ch ...

What is the best way to pass an array to PHP and then display it in HTML?

After setting up a form with 3 select tags in my HTML, I attempted to create an array using jQuery and send it to PHP. The goal is to retrieve data from PHP and display it on my HTML page. Below is the code snippet: HTML code <form name="myform"> ...

What is the method for sending an object to a concealed form within php?

I am faced with a challenge involving an object named $todovalues and a form. The task at hand is to pass the entire todovalues object through the form. Here is how my form is structured - <form action="" method="post"> <input class="todobuttons ...

Tips for updating form tag details within the same blade file upon reloading

I have set up a payment page that displays the total amount to be paid. To facilitate payments through a 3rd party gateway, I have utilized a form tag on the page. Now, I am looking to integrate a promo code feature on this payment page so that the total a ...

Dynamic number of parameters in Laravel routes

I'm attempting to develop a route that includes a mandatory parameter followed by an indefinite number of parameters. The exact count of additional parameters is uncertain, but it will always be more than zero. <?php Route::get('{tree_slug}/{ ...

Generating a JSON response in PHP without the use of brackets []

I am attempting to send a JSON response like this: {"id":13,"user_id":4,"play_list_name":"My Play List12","section":1,"created":"2017-04-14T05:46:47+00:00","status":1} However, the web service is producing JSON as follows: [{"id":13,"user_id":4,"play_li ...

Issue with passing PHP session variable during AJAX request processing

I've been working on a script that echoes different answers based on selected values. Right now, I'm just testing with one value but plan to expand later on. The PHP script is triggered through AJAX so the results display on the same page. Howev ...

Child element failing to resize along with parent container

Here is the HTML structure I have for a template.php page within my website. <!DOCTYPE html> <html lang="en"> <head> <title></title> ...... </head> <body> <div id="container"> ...

Using PHP's exec() function to manipulate character encoding via the command line

I've been struggling to pass UTF-8 text as an argument to a command line program using the exec function in PHP. It seems like there are some issues with character encoding causing trouble. When I run locale charmap from the terminal, it returns: UTF ...

The issue with Laravel Elixir BrowserSync not displaying the page

After checking out the latest episode on TechSavy Forums () I was inspired to experiment with CodePen for web development. First, I followed the usual steps for starting a new project: npm init cd project npm install Next, I attempted to access the Code ...

After clicking the submit button, how can I eliminate the following: "config.php?username=++psw&Text=psw&submit=send?" and remain on the same page?

Whenever I hit the submit button on my form, PHP completes its task but instead of staying on the page (or simply reloading it), I am redirected to the same URL with '/config.php?username=technologies.%0D%0A++&submit = Send ". Is there a way ...

Querying with Codeigniter in Ajax Data table only returns a single row

When using codeigniter to create an ajax data-table, I pass the User ID as a condition to retrieve records from a product orders table. $this->datatables->select('orders.order_user_id,orders.order_date,orders.order_id,orders.order_confirmation_ ...

Limit users to viewing a Joomla article only once

I'm trying to figure out a way to customize Joomla so that only one view of certain articles is allowed per user. My goal is to make the article appear grayed out and prevent users from clicking on it after they have viewed it once. If anyone has any ...