sonicthehedgehog Posted September 8, 2015 Share Posted September 8, 2015 I'm trying to get the details from a cvs file into a database but I also want to check if the results are there already. If they are then I want to update them if not I want to then insert them. This is what I've got but every time I try I get a 500 error $query="select feed,file,name from dealer where enabled = 1"; $csv_convert=dbselect( $query,"dbLinkInt" );if( is_array( $csv_convert ) ) { foreach( $csv_convert as $key=>$value ) { $url = $value['feed']; file_put_contents("".$value['filename'].".csv",gzdecode(file_get_contents($url))); $handle = fopen($value['filename'].".csv", "r"); while (($data = fgetcsv( $handle )) !== FALSE) {$gender="0"; # create product $query="select dealer_product_id from feeds"; $productid=dbupdate( $query,"dbLinkInt" ); if ( $productid!=$data[0] ) { $query="insert into feeds set dealer_product_id =".dbstr( $data[0] ).", dealer_link =".dbstr( $data[3] ).",image_url=".dbstr( $data[4] ).",price=".dbstr( $data[5] ).",product_name=".dbstr( $data[7] ).",product_url=".dbstr( $data[8] ).",delivery_cost=".dbstr( $data[14] ).",ean=".dbstr( $data[19] ).",product_brand=".dbstr( $data[20] ).",brand_name=".dbstr( $value['name'] ).",promo_text=".dbstr( $data[21] ).",large_image=".dbstr( $data[22] ).",enabled=".dbstr( $data[23] ); $newid=dbupdate( $query,"dbLinkInt" ); $query="insert into text_store set tablename='product_detail', owner_id=$newid, type='paragraph', text=".dbstr( $data[6] ).", instance=1"; dbupdate( $query,"dbLinkInt" ) or die(mysql_error());} else { $query="update feeds set dealer_link=".dbstr( $data[3] ).",image_url=".dbstr( $data[4] ).",price=".dbstr( $data[5] ).",product_name=".dbstr( $data[7] ).",product_url=".dbstr( $data[8] ).",delivery_cost=".dbstr( $data[14] ).",ean=".dbstr( $data[19] ).",product_brand=".dbstr( $data[20] ).",brand_name=".dbstr( $value['name'] ).",promo_text=".dbstr( $data[21] ).",large_image=".dbstr( $data[22] ).",enabled=".dbstr( $data[23] )." where aw_product_id=".dbstr( $data[0] ); $query="update text_store set tablename='product_detail', owner_id=".dbstr( $data[0] ).", type='paragraph', text=".dbstr( $data[6] ).", instance=1"; dbupdate( $query,"dbLinkInt" ) or die(mysql_error());}}fclose($handle); } } print "Import done"; If I don't bother checking the results before hand then I can insert them no problems it's just when I try and see if they already exist I get stuck Link to comment Share on other sites More sharing options...
justsomeguy Posted September 8, 2015 Share Posted September 8, 2015 You need to get the actual error message, depending on how your server is configured it might be sending error messages to a log file, or it might just be hiding them altogether. You'll need to change that so you can find them. Link to comment Share on other sites More sharing options...
sonicthehedgehog Posted September 9, 2015 Author Share Posted September 9, 2015 It appears to be hiding them completely. I did try changing the .htaccess file to show them but that still didn't show them Link to comment Share on other sites More sharing options...
justsomeguy Posted September 9, 2015 Share Posted September 9, 2015 For non-syntax errors you can set them at runtime also. ini_set('display_errors', 1);error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
sonicthehedgehog Posted September 10, 2015 Author Share Posted September 10, 2015 (edited) thanks, I tried that but still didn't get anything. This is the code I've got at the moment ini_set('display_errors', 1);error_reporting(E_ALL);$query="select feed,file,name from dealer where enabled = 1"; $csv_convert=dbselect( $query,"dbLinkInt" );if( is_array( $csv_convert ) ) { foreach( $csv_convert as $key=>$value ) { $url = $value['feed']; file_put_contents("".$value['filename'].".csv",gzdecode(file_get_contents($url))); $handle = fopen($value['filename'].".csv", "r"); while (($data = fgetcsv( $handle )) !== FALSE) {$gender="0"; # create product $query="update feeds set dealer_link=".dbstr( $data[3] ).",image_url=".dbstr( $data[4] ).",price=".dbstr( $data[5] ).",product_name=".dbstr( $data[7] ).",product_url=".dbstr( $data[8] ).",delivery_cost=".dbstr( $data[14] ).",ean=".dbstr( $data[19] ).",product_brand=".dbstr( $data[20] ).",brand_name=".dbstr( $value['name'] ).",promo_text=".dbstr( $data[21] ).",large_image=".dbstr( $data[22] ).",enabled=".dbstr( $data[23] )." where aw_product_id=".dbstr( $data[0] ); $query="update text_store set tablename='product_detail', owner_id=".dbstr( $data[0] ).", type='paragraph', text=".dbstr( $data[6] ).", instance=1"; dbupdate( $query,"dbLinkInt" ) or die(mysql_error());}fclose($handle); } } print "Import done"; If I add my own information to the query (i.e.: dealer='www.domain.com') it works but when I try to do it from the feed (which is the same feed I used to add the products nothing happens Edited September 10, 2015 by sonicthehedgehog Link to comment Share on other sites More sharing options...
justsomeguy Posted September 10, 2015 Share Posted September 10, 2015 So it doesn't print that final message? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now