Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update not working?

Status
Not open for further replies.

shadiadi

Programmer
Dec 19, 2008
4
TH
Hi some help here would be appreciated my update isn't working everything in this statement updates except $file1 $file2 which are blob fields. After the update they just stay as [BLOB 0]??


Code:
$file1 = (fread(fopen($data2,0,"data2")));
$file2 = (fread(fopen($thumbnail2,0,"thumbnail2")));
$sql02 = "update zloads set description1 = '$description2', data1 = '$file1', filename1 = '$filename2', filesize1 = '$filesize2', filetype1 = '$filetype2', thumbnail1 = '$file2', thumbnailtype1= '$thumbnailtype2' where intProductID='$id'";
 
you have not escaped the fields before using them in your data.

i would also recommend that you use file_get_contents() instead of the concatenated fread(fopen()) construct.

Code:
$sql02 = "update zloads set description1 = '$description2', data1 = '[red]".mysql_real_escape_string($file1)."[/red]', filename1 = '$filename2', filesize1 = '$filesize2', filetype1 = '$filetype2', thumbnail1 = '[red]".mysql_real_escape_string($file2)."[/red]', thumbnailtype1= '$thumbnailtype2' where intProductID='$id'";
 
of course, i should add that storing blobs in a database is seldom a good idea. store files in the file system and pointers to them in the database.
 
mmm i just tried

Code:
$file1 =  file_get_contents($data2, "r");
$file2 =  file_get_contents($thumbnail2, "r");
$sql02 = "update zloads set description1 = '$description2', data1 = '".mysql_real_escape_string($file1)."', filename1 = '$filename2', filesize1 = '$filesize2', filetype1 = '$filetype2', thumbnail1 = '".mysql_real_escape_string($file2)."', thumbnailtype1= '$thumbnailtype2' where intProductID='$id'";

and got the error

Code:
Warning: file_get_contents(‰PNG  ) [function.file-get-contents]: failed to open stream: No such file or directory in /home/hmtcompa/public_html/user/myaccount/updatepics.php on line 59

Warning: file_get_contents(ÿØÿà) [function.file-get-contents]: failed to open stream: No such file or directory in /home/hmtcompa/public_html/user/myaccount/updatepics.php on line 60

Warning: Cannot modify header information - headers already sent by (output started at /home/hmtcompa/public_html/user/myaccount/updatepics.php:59) in /home/hmtcompa/public_html/user/myaccount/updatepics.php on line 69

$data2 & thumbnail2 are already blobs stored in the database not posted from the previous page i am doing an sql query to call all the row data to this page in the header happy new year by the way ;)
 
file_get_contents() takes only one (main) argument. you do not need to specify read/write etc since it is inherent within the _get_ and _put_ (of its sister function).

i'm not sure what you mean by $data2 is already a blob. By your use of fopen i had understood them to represent files (i.e. filenames and paths). If the actual image data is already in these variables you do not need to use fopen/fread or anything in order to handle them. just use them as you would any string.

Happy New Year, likewise!
 
solved it with this

Code:
$file1 = $row["data2"]; 
$file1 = mysql_real_escape_string($file1); 
$file2 = $row["thumbnail2"]; 
$file2 = mysql_real_escape_string($file2); 
$sql02 = "update zloads set description1 = '$description2', data1 = '$file1', filename1 = '$filename2', filesize1 = '$filesize2', filetype1 = '$filetype2', thumbnail1 = '$file2', thumbnailtype1 = '$thumbnailtype2' where intProductID='$id'";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top