473,783 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,howev er 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_publi cacion , not_archivo_c_n ame , not_archivo_c_t ype ,
not_archivo_c_s ize , not_archivo_c_c ontent , not_archivo_r_n ame ,
not_archivo_r_t ype , not_archivo_r_s ize , not_archivo_r_c ontent )
VALUES (NULL , '', 'Cris', '', , 'noticia.pdf', 'application/pdf',
'15581','$conte nt', 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($tmpNa me));
$content = addslashes($con tent);
fclose($fp);

if(!get_magic_q uotes_gpc())
{
$fileName = addslashes($fil eName);
}

$query = la que les pase

mysql_query($qu ery, $connection_str ing) 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_publ icacion` 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 5376
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,howev er 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_publi cacion , not_archivo_c_n ame , not_archivo_c_t ype ,
not_archivo_c_s ize , not_archivo_c_c ontent , not_archivo_r_n ame ,
not_archivo_r_t ype , not_archivo_r_s ize , not_archivo_r_c ontent )
VALUES (NULL , '', 'Cris', '', , 'noticia.pdf', 'application/pdf',
^ This us not valid
'15581','$conte nt', 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($tmpNa me));
$content = addslashes($con tent);
fclose($fp);

if(!get_magic_q uotes_gpc())
{
$fileName = addslashes($fil eName);
}

$query = la que les pase

mysql_query($qu ery, $connection_str ing) 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_publ icacion` 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*******@attgl obal.net
=============== ===
Mar 6 '07 #2

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

Similar topics

5
12026
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
34336
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
6879
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 have to insert is in the form of byte array. My problem is that the bulk inserts happen only as long as the length of array is less than 4K. Any data more than 4K gets truncated. Is it possible to do bulk inserts in a BLOB field with data more...
3
4726
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 2Mb) are stored in BLOB column. The amount of documents for the first year should not exceed 5/6 Giga, but I cannot make prevision for the next years. Those documents are mainly just accessed (update and delete are not so
1
14548
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 "I am a test" instead of BLOB-value?
11
23032
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
6534
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 retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the...
1
3573
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 characters in the xml string when inserting. e.g i am using insert into table values('test','test','test','xmlstring') Some rows go through but other records do not so does anyone know how i could insert an xml stirng which is everything from...
2
5052
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 up this way and i'm able to insert text data into it with no problems. I've checked the database design its basiclly a duplicate. I did have to remove my not null on the long blob element. but other then that, i don't understand why this is...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.