473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I can't insert a blob value in MySQL

Hello guys!
This is Cristian From Argentina, and I wanted to ask you some help,
I've looking on this and it makes me mad, I found that the error is in
the $content , when y try to insert the record into the table via PHP
code i receive an error message saying that the sin taxis its
incorrect,however if i print the query echo ($query) and i copy and
paste the query in the PHPmyAdmin the insert executes successfully.

the $content variable contents the binary part of the file, in fact
the file

I'm pretty sure that the issue is with the $content variable via PHP
since , if i omit this field

the query via PHP executes successfully.

I've included a part of the code, the Table structure and the Query
string I'm using.

I hope you can help,

Please let me know if u need further information,

Your help is greatly Appreciated.

Thanks in advance
g
Cristian Garofalo

INSERT INTO T_NOTICIAS ( not_id , not_cod , not_nombre , not_detalle ,
not_fecha_publicacion , not_archivo_c_name , not_archivo_c_type ,
not_archivo_c_size , not_archivo_c_content , not_archivo_r_name ,
not_archivo_r_type , not_archivo_r_size , not_archivo_r_content )
VALUES (NULL , '', 'Cris', '', , 'noticia.pdf', 'application/pdf',
'15581','$content', NULL , NULL , NULL ,'')
if(isset($_POST['upload']) && $_FILES['userfile']['size'] 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

$query = la que les pase

mysql_query($query, $connection_string) or die(mysql_error());

}

CREATE TABLE `T_NOTICIAS` (
`not_id` int(100) NOT NULL auto_increment,
`not_cod` varchar(5) NOT NULL default '///',
`not_nombre` varchar(30) NOT NULL default '',
`not_detalle` varchar(100) default NULL,
`not_fecha_publicacion` varchar(10) default NULL,
`not_archivo_c_name` varchar(30) default NULL,
`not_archivo_c_type` varchar(30) default NULL,
`not_archivo_c_size` int(11) default NULL,
`not_archivo_c_content` blob,
`not_archivo_r_name` varchar(30) default NULL,
`not_archivo_r_type` varchar(30) default NULL,
`not_archivo_r_size` int(11) default NULL,
`not_archivo_r_content` blob,
UNIQUE KEY `not_id` (`not_id`),
UNIQUE KEY `not_id_4` (`not_id`),
KEY `not_id_2` (`not_id`),
KEY `not_id_3` (`not_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

Mar 5 '07 #1
1 5333
cricrin wrote:
Hello guys!
This is Cristian From Argentina, and I wanted to ask you some help,
I've looking on this and it makes me mad, I found that the error is in
the $content , when y try to insert the record into the table via PHP
code i receive an error message saying that the sin taxis its
incorrect,however if i print the query echo ($query) and i copy and
paste the query in the PHPmyAdmin the insert executes successfully.

the $content variable contents the binary part of the file, in fact
the file

I'm pretty sure that the issue is with the $content variable via PHP
since , if i omit this field

the query via PHP executes successfully.

I've included a part of the code, the Table structure and the Query
string I'm using.

I hope you can help,

Please let me know if u need further information,

Your help is greatly Appreciated.

Thanks in advance
g
Cristian Garofalo

INSERT INTO T_NOTICIAS ( not_id , not_cod , not_nombre , not_detalle ,
not_fecha_publicacion , not_archivo_c_name , not_archivo_c_type ,
not_archivo_c_size , not_archivo_c_content , not_archivo_r_name ,
not_archivo_r_type , not_archivo_r_size , not_archivo_r_content )
VALUES (NULL , '', 'Cris', '', , 'noticia.pdf', 'application/pdf',
^ This us not valid
'15581','$content', NULL , NULL , NULL ,'')
if(isset($_POST['upload']) && $_FILES['userfile']['size'] 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

$query = la que les pase

mysql_query($query, $connection_string) or die(mysql_error());

}

CREATE TABLE `T_NOTICIAS` (
`not_id` int(100) NOT NULL auto_increment,
`not_cod` varchar(5) NOT NULL default '///',
`not_nombre` varchar(30) NOT NULL default '',
`not_detalle` varchar(100) default NULL,
`not_fecha_publicacion` varchar(10) default NULL,
`not_archivo_c_name` varchar(30) default NULL,
`not_archivo_c_type` varchar(30) default NULL,
`not_archivo_c_size` int(11) default NULL,
`not_archivo_c_content` blob,
`not_archivo_r_name` varchar(30) default NULL,
`not_archivo_r_type` varchar(30) default NULL,
`not_archivo_r_size` int(11) default NULL,
`not_archivo_r_content` blob,
UNIQUE KEY `not_id` (`not_id`),
UNIQUE KEY `not_id_4` (`not_id`),
KEY `not_id_2` (`not_id`),
KEY `not_id_3` (`not_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

Correct your syntax and it should work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alper Adatoz | last post by:
Hi, i have a little problem. i hope u guys give me a clear solution (: db: mssql i just want to put jpeg file to the image field at the mssql db. and after that i want to call it back..
3
by: Frank Natoli | last post by:
Having created a table with a longblob column, what is the insert syntax to set the value of the longblob column? The data will be read from a file.
2
by: Niraj | last post by:
Hi, I am trying to do bulk insert of binary data (array of bytes) in an Oracle table. The data type of the table is BLOB. I am using Oracle Objects for OLE (OO4O) in C++. The binary data that I...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
1
by: Markus | last post by:
This is my TABLE: CREATE TABLE test( data BLOB ) This is my INSERT: INSERT INTO test(data) VALUES (CAST('I am a test' AS BLOB)) But how can I SELECT the data as VARCHAR, so that I can see...
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
2
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these...
1
by: jonathan184 | last post by:
Hi I am trying to insert a long XML string in a blob field in mysql. So i am just using a normal insert statement is there an xml function i could use. This way I do have to keep escaping special...
2
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.