I have installed the jQuery file upload plugin. I have edited the upload handler file to insert the image name at database. Everything works fine but I got this error:
SyntaxError: Unexpected token < in JSON at position 0
After I refresh the page I see the file moved to the correct position and database updated all OK, but keep getting this error every time I upload something.
Here is the code I inserted to options array for database connection:
'database' => 'easywp_casino',
'host' => 'localhost',
'username' => 'root',
'password' => '',
This code I insert in handle_file_upload function:
$file->upload_to_db = $this->add_img($name);
and this is the code for database image name insert which I add after the handle_file_upload function:
function query($query) {
$database = $this->options['database'];
$host = $this->options['host'];
$username = $this->options['username'];
$password = $this->options['password'];
$link = mysql_connect($host,$username,$password);
if (!$link) {
die(mysql_error());
}
$db_selected = mysql_select_db($database);
if (!$db_selected) {
die(mysql_error());
}
$result = mysql_query($query);
mysql_close($link);
return $result;
}
function add_img($name) {
$add_to_db = $this->query("INSERT INTO files
(type, item_id, image)
VALUES
('0', '12', '".$name."')") or die(mysql_error('new_error'));
return $add_to_db;
}
( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in D:\wamp\www\cmslaravel2\public\backend\assets\server\items\Upload – Adam Ibrahim Oct 02 '16 at 10:57