Phpmysql insertion in jquery-file-upload

Source: Internet
Author: User
Phpmysql insertion of jquery-file-upload recently used jquery-file-upload to improve website upload experience

Https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration
The upload was completed immediately according to his reference documents. at the beginning, I tried it according to his SQL architecture.

After the results are uploaded, they can be inserted successfully. json is returned to the page and everything is normal!

But the problem is that his SQL architecture... there is a url

However, the author does not seem to have processed the SQL statement in PHP.

Let me change it ,....

Some basic configurations are added first.
$dir = $_COOKIE["uid"].'/'.date("Y").'/'.date("m").'/'.date("d").'/';$dirUP =  "../../../att/".$dir;$dirLink =  $dir;$options=array(    'upload_dir' => $dirUP,    'upload_url' => $dirLink,    'delete_type' => 'POST',    'db_host' => 'localhost',    'db_user' => 'root',    'db_pass' => '*****',    'db_name' => '*****',    'db_table' => 'files');



It should be this paragraph ....

I tried multiple times and failed to add the url field [original document code]
    protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,            $index = null, $content_range = null) {        $file = parent::handle_file_upload(            $uploaded_file, $name, $size, $type, $error, $index, $content_range        );        if (empty($file->error)) {            $sql = 'INSERT INTO `'.$this->options['db_table']                .'` (`name`, `size`, `type`, `title`, `description`)'                .' VALUES (?, ?, ?, ? , ?)';            $query = $this->db->prepare($sql);            $query->bind_param(                'sisss',                $file->name,                $file->size,                $file->type,                $file->title,                $file->description            );            $query->execute();            $file->id = $this->db->insert_id;        }        return $file;    }


Show me all:
Warning: mysqli_stmt: bind_param (): Number of elements in type definition string doesn't match number of bind variables in

What does this mean? Does it mean I add less?
I have changed it to... so that all the type fields in step 5 are added with the url, which is a quantity problem?

    protected function handle_file_upload($uploaded_file, $name, $size, $type,$url, $error,            $index = null, $content_range = null) {        $file = parent::handle_file_upload(            $uploaded_file, $name, $size, $type,$url, $error, $index, $content_range        );        if (empty($file->error)) {            $sql = 'INSERT INTO `'.$this->options['db_table']                .'` (`name`, `size`, `type`, `url`, `title`, `description`)'                .' VALUES (?, ?, ?, ?,? , ?)';            $query = $this->db->prepare($sql);            $query->bind_param(                'sisss',                $file->name,                $file->size,                $file->type,                $file->url,                $file->title,                $file->description            );            $query->execute();            $file->id = $this->db->insert_id;        }        return $file;    }


Save
$ Url = $ _ COOKIE ["uid"]. '/'. date ("Y "). '/'. date ("m "). '/'. date ("d "). '/'. filename

How to change it? Can I use $ file-> url directly?




In addition, because of this stuff, I still got an append value problem. if you are familiar with jq, you can also help your younger brother.
Http://bbs.csdn.net/topics/390862894


Reply to discussion (solution)

Warning: mysqli_stmt: bind_param (): Number of elements bound to variables that do not match the type-defined string
Isn't that clear?
$ Query-> bind_param (
'Siss', // How can I have only five types of declarations?
$ File-> name, // 1
$ File-> size, // 2
$ File-> type, // 3
$ File-> url, // 4
$ File-> title, // 5
$ File-> description // 6: 6 in total
);

Warning: mysqli_stmt: bind_param (): Number of elements bound to variables that do not match the type-defined string
Isn't that clear?
$ Query-> bind_param (
'Siss', // How can I have only five types of declarations?
$ File-> name, // 1
$ File-> size, // 2
$ File-> type, // 3
$ File-> url, // 4
$ File-> title, // 5
$ File-> description // 6: 6 in total
);


Oh... it turns out this problem

Solved successfully!

I used to switch to pdo after using mysql_query. I have never used mysqli, and PDO seems to have never mentioned this method.

Thank you for learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.