By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

I can't insert a blob value in MySQL

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.