Page 1 of 1

Inserting a blob

Posted: Thu Dec 31, 2009 8:59 am
by NikBruce
Hi,

I've been trying to upload a file to a mysql table all day.

here is the table:

Code: Select all

 
$cv = "CREATE TABLE `$proName` (
`id`   Int Unsigned Not Null Auto_Increment,
`name` VarChar(255) Not Null Default 'Untitled.txt',
`mime` VarChar(50) Not Null Default 'text/plain',
`size` BigInt Unsigned Not Null Default 0,
`data` MediumBlob Not Null,
`createdDate` DateTime Not Null,
`createdBy` VarChar(50) Not Null,
PRIMARY KEY (`id`)
)";
 
and here is the insert:

Code: Select all

 
$ti = "INSERT INTO '$proName' (name, mime, size, data, createdDate, createdBy)
VALUES ('$name', '$mime', '$size', '$data', '$date', '$accName')";
 
$result = "mysql_query($ti, $con)";
 
if ($result)
{ echo "Success. "; }
else
{ echo "Fail. "; }
 
The table gets created just fine, but the insert query doesn't work. It echos "success," but the table remains empty.

I've tried writing the insert query a bunch of different ways, but nothing changes.

please help. thanks

Re: Inserting a blob

Posted: Thu Dec 31, 2009 9:09 am
by AbraCadaver
Ummm... Because you have quotes around the mysql_query() function. :roll:

Re: Inserting a blob

Posted: Thu Dec 31, 2009 10:43 am
by NikBruce
if the quotes aren't there it echos "Fail"

Re: Inserting a blob

Posted: Thu Dec 31, 2009 11:16 am
by AbraCadaver
NikBruce wrote:if the quotes aren't there it echos "Fail"
That's because it actually executes the query and it fails. With the quotes around the function call the function is never called. You have just assigned a string of characters to the $result var. You need to turn on error reporting to see why the query fails.

Re: Inserting a blob

Posted: Thu Dec 31, 2009 12:07 pm
by NikBruce
i used

Code: Select all

<?php error_reporting(-1); ?>
no errors appeared.

Re: Inserting a blob

Posted: Thu Dec 31, 2009 12:31 pm
by AbraCadaver

Code: Select all

$result = mysql_query($ti, $con) or die(mysql_error());

Re: Inserting a blob

Posted: Thu Dec 31, 2009 2:45 pm
by NikBruce
thanks.

i got a,
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''EU Observatory' (name, mime, size, data, createdDate, createdBy) VALUES ('img3' at line 1
i guess i should have done that first.

Happy new year.

Re: Inserting a blob

Posted: Thu Dec 31, 2009 2:51 pm
by AbraCadaver
NikBruce wrote:thanks.

i got a,
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''EU Observatory' (name, mime, size, data, createdDate, createdBy) VALUES ('img3' at line 1
i guess i should have done that first.

Happy new year.
Yeah, EU Observatory is not a valid table name and also I don't think it will like quotes around it. Maybe backticks `

Re: Inserting a blob

Posted: Fri Jan 01, 2010 12:57 am
by NikBruce
the problem was that i hadn't run the variables through a real_escape_string.

Thanks for all your help.