I can't insert a blob value in MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cricrin

    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 ;

  • Jerry Stuckle

    #2
    Re: I can't insert a blob value in MySQL

    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...