Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts

    BLOBing an Excel File

    Hello,

    I am trying to read a Microsoft Excel file into a database.. here is the code I am using:

    PHP Code:
    $svcSheetHdl fopen($_FILES['svcSheet']['tmp_name'], "r");
    $svcSheetContent fread($svcSheetHdl$_FILES['svcSheet']['size']);
    $svcSheetContent addslashes $svcSheetContent );
    fclose$svcSheetHdl ); 
    Then I simply put $svcSheetContent in an INSERT statement and run it. Unfortunately, I don't think addslashes is working correctly. Some of the quotes within the BLOB data are being read, even though they have been escaped, or should have been. I have tried using mysql_real_escape_string() and addslashes() and neither of them work. I have used this method before with no problem whatsoever, is this something with excel files?

    What should I do, any ideas?

    Any help is greatly appreciated.

    Thanks,

    FuZion

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Some of the quotes within the BLOB data are being read, even though they have been escaped, or should have been.
    Are you getting an error when you INSERT or when you SELECT the data? Post any error messages... Give an example of what you see that shows the problem.

    Also, what are the settings for - magic_quotes_runtime and magic_quotes_sybase?

    Edit: I guess I recommend you show your code that is inserting the data into the database as well.
    Last edited by CFMaBiSmAd; 08-09-2007 at 05:45 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I am getting the error when I insert it, there are no error messages, the query just does not work. What I did was echoed the query to the page, then ran it in MySQL Query Browser. It gives me: "there is an error in your SQL syntax near: XXXXX" and then gives some of the blob code. I know it is not reading the entire thing as a string because of the way Query Browser color codes its syntax, only some of the BLOB is orange (a string), you can see where the quotes change it.

    I'm not sure, would I find those values in my.ini?

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Since you are receiving a syntax error in the query browser, your PHP script is also probably failing, but has no error checking or error reporting. Post your code to get any specific help with it. It is likely that your query is not formed correctly.

    I just whipped up an upload/database insert script based on the code you posted above, and it works with a moderate size/complexity .xls file.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Here is the code:

    Code:
    $svcSheetHdl = fopen($_FILES['svcSheet']['tmp_name'], "r");
    		$svcSheetContent = fread($svcSheetHdl, $_FILES['svcSheet']['size']);
    		$svcSheetContent = addslashes ( $svcSheetContent );
    		fclose( $svcSheetHdl );
    			
    				
    		$query = "INSERT INTO `svcSheet` ( aid, date, number, xls_data ) VALUES ( " . $aid . ", STR_TO_DATE('" . $_POST['date'] . "', '%m/%d/%Y'), " . $_POST['number'] . ", '" . $svcSheetContent . "' )";
    The query works fine without the xls data, but doesn't work with it, I have used this exact same method before with no problems so I'm not sure whats up.

    Thanks a bunch for your help!

  • #6
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Could it be my PHP and/or MySQL settings?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •